Disable FCFS (File Modification Monitoring)

Source: Internet
Author: User

You may know that modifying some specific files and directories on the site will cause the whole site to restart or recompile. Maybe you don't pay attention to it. You don't know how to delete or rename any directory under the site, which will cause the whole site to restart (adding the Directory won't ). This problem is actually the root cause of many Session loss. For example, you can also find many examples of the problem that Session loss is caused by changes in the directory structure of ASP. NET 2.0.

This is actually an "elaborate" design of ASP. NET 2.0, because in many cases. ASP. NET caches a large number of resources. If the directory is not monitored, some deleted resources may still be used, resulting in leakage of other unnecessary resources. Through this article, we can find some conditions that may cause site restart. The first one is that deleting or renaming directories will cause site restart.

This problem is early in ASP. NET 2.0 was discovered when it was just released and has been specially discussed in Deleting ASP. NET 2.0 Application Sub-Directories Shuts Down the AppDomain, a solution is also proposed in the article, but the approach is too complicated. The ideal solution is to have related patches to solve the problem. Fortunately, we can find the patch here and introduce how to configure it to solve the problem.

Solution: The mechanism for deleting or renaming the monitoring directory is File Change configurations (FCNs). This patch is used to set the switch for disabling or enabling FCNS, we only need to disable FNCS to avoid this problem.

Practice: The current ASP. NET 2.0 has reached SP2, and we do not need to install this patch separately. We only need to perform one step in the Registry to solve this problem. Add a DWORD Value named FCNMode in HKLM \ Software \ Microsoft \ ASP. NET. It should not exist by default and Its Value Meaning is:

Does not exist
This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory.

0 or greater than 2
This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory.

The application will disable File Change specifications (FCNs ).

The application will create one object to monitor the main directory. The application will use this object to monitor each subdirectory.

Set the value to 1 to disable FCNS. More detailed can take the test: http://support.microsoft.com/kb/911272

Exit the registry and restart IIS. The problem can be solved.

Note: Session loss is only a side effect of AppDomain restart. It is not the focus of this article. It is only used to optimize the title when someone else finds the problem. In addition, there are many reasons for site restart. You can refer to the above link and will not describe it here.

Note: If you disable FCNs, no matter whether you modify the Web. config or BIN directory, the whole site will not be restarted. I think this will also bring us some new problems, such as cache expiration issues. Choose whether to disable it. :(


In addition, you can use code to monitor directory changes without affecting changes to the bin directory and web. config.

public class StopFileMonitorModule : IHttpModule
#region IHttpModule Members

public void Dispose()


public void Init(HttpApplication context)
PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
object o = p.GetValue(null, null);
FieldInfo f = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.