Solution to server restart caused by modifying IIS website file structure

Source: Internet
Author: User

A project is being created in the group, using the set of ASP. NET. The project needs to decompress the MP3 audio file and extract its coefficient. In this case, an external EXE executable file is used. The most annoying thing is that every time the page is executed halfway, a "thread abort exception" (system. Threading. threadabortexception) will be thrown ). The prompt is as follows:

"/" Indicates a server error in the application.
The thread is being aborted.
Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code.
Exception details: system. Threading. threadabortexception: The thread is being aborted.
Source error:
An unhandled exception is generated during the execution of the current Web request. You can use the following exception stack trace information to determine the cause and location of the exception.
Stack trace:
[Threadabortexception: The thread is being aborted.]
System. Web. httpapplication. executestep (iexecutionstep step, Boolean & completedsynchronously) + 303
System. Web. applicationstepmanager. resumesteps (Exception error) + 762
System. Web. httpapplication. system. Web. ihttpasynchandler. beginprocessrequest (httpcontext context, asynccallback CB, object extradata) + 211
System. Web. httpruntime. processrequestinternal (httpworkerrequest wr) + 452

When I get off work, I find it on a foreign site.
To the solution. Interestingly, the foreign friend said
"I killed hours playing with Timeouts and configs before finding the solution ."
(I spent several hours playing with the "timeout" attribute and the configuration file ). I can't help but lament that the verb phrase "Play with" is well-developed.
To put it bluntly, because the error time is two minutes, like this foreign friend, I was immediately misled to the "timeout" setting. As a result, I changed the file upload, page processing, IIS request timeout, Session Timeout, and other settings to dozens of minutes. The error remains the same. This is not the case until you read this webpage.
 
The cause of the problem is that IIS has a new "File Change configurations (fcns)", ASP 2.0's so-called "safer and more stable" feature, which is
It is used to monitor whether the file structure or content under the web site directory is "greatly changed ". If the site is changed, the site is automatically restarted. This feature mainly takes into account that ASP. NET caches a lot of resources.
If the directory is not monitored for changes, some deleted resources may still be used, resulting in leakage of other unnecessary resources.
 
I immediately think of a problem that has never been solved before: deleting or renaming any directory or XML file under the site will lead to the loss of session, from global. asax (said
It's a bad design, but I think it's okay. The strengths and weaknesses coexist .) The running log shows that web programs often restart inexplicably. When debugging Visual Studio 2008
The built-in lightweight Web server does not have these problems. The problem lies here.
Let's talk about the cause of the incident. The intuitive idea is to disable fcns. It is estimated that Microsoft later realized that fcns is not only good but not good. Therefore, an ASP. NET 2.0 SP2 service was released to disable the fcns function. Then you have three ways:
(1) modify the Registry
Add a DWORD Value named fcnmode under HKLM \ Software \ Microsoft \ ASP. NET. It should not exist by default and Its Value Meaning is:
Does not exist, or is not equal to 1 and not equal to 2: This is the default action. For each subdirectory, the application creates an object to monitor this directory.
Value: 1: The application disables fcns.
Value 2: The application creates an object monitoring home directory, which is used by the application to monitor each sub-directory.
Obviously, if the value of fcnmode is set to 1, you can disable FCFS. Finally, restart IIS.
(2) modify the code
Add the following code to global. asax (or its. CS file) to turn off fcns ).

Using system. reflection;
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 [] {});

Other methods, such as the ihttpmodule method, are essentially the same as global. asax. This is part of how to use the httpmodule function, which is not described here.
(3) Good Programming habits
You can move the frequently modified directories out and create a page to download the files in the folder to improve security. For example, manage the "user directory" of the information system. This method can avoid unnecessary resource leaks.

Http://www.cnblogs.com/LoriMoon/archive/2010/11/21/1883521.html

 

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.