asp.net delete project files/folders IIS reboot, session loss problem _ practical tips

Source: Internet
Author: User
In a closer look, SSO returned ticket, only to find that the original IIS restarted, the final solution is as follows:

Create a new class to inherit IHttpModule
Copy Code code as follows:

<summary>
Stops the ASP.net AppDomain being restarted (which clears
Session state, Cache etc.) Whenever a folder is deleted.
</summary>
public class Stopappdomainrestartonfolderdeletemodule:ihttpmodule
{
private static bool Disablefcns = FALSE;
public void Init (HttpApplication context)
{
if (DISABLEFCNS) return;
PropertyInfo p = typeof (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[] {});
Disablefcns = true;
}
public void Dispose () {}
}

Then add the module configuration in Web.config
Copy Code code as follows:

<!--resolve IIS restart caused by deleting project files/Folders-->
<add name= "Stopappdomainrestartonfolderdelete" type= " Deployassistant.facade.web.stopappdomainrestartonfolderdeletemodule,deployassistant.facade "/>

So every time you delete the file/folder AppDomain will not restart, the session will not be lost. The world is getting better!

Changes under the PS:Web.Config and Bin folders will still allow the Web to restart, which must be preserved!
Related Article

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.