Does ASP.NET really do that?

A coworker told me that he noticed slow performance on our website when folders were deleted in the solution. We do not usually need to delete folders during production use, but he wanted me to look into it.

Sure enough, I was able to reproduce this behavior, furthermore I found others that had experienced the same problem, and a workaround.

void Application_Start(object sender, EventArgs e)
{
    // prevent file changes monitoring on subdirectories
    PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty(
        "FileChangesMonitor",
        BindingFlags.NonPublic | 
        BindingFlags.Public | 
        BindingFlags.Static);

    FieldInfo f = p.GetValue(null, null).GetType().GetField(
        "_dirMonSubdirs",
        BindingFlags.Instance |
        BindingFlags.NonPublic |
        BindingFlags.IgnoreCase);

    object monitor = f.GetValue(p.GetValue(null, null));
    MethodInfo m = monitor.GetType().GetMethod(
        "StopMonitoring",
        BindingFlags.Instance | BindingFlags.NonPublic);

    m.Invoke(monitor, new object[] { }); 
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s