session loss processing method

Source: Internet
Author: User
Tags custom name

Add Name= "Stopappdomainrestartonfolderdelete"
Type= "Mywebsite.stopappdomainrestartonfolderdeletemodule"/>
It should be noted that "Stopappdomainrestartonfolderdelete" is a custom name, "Mywebsite" is a namespace in the above. cs file, typically the project name. " Stopappdomainrestartonfolderdeletemodule "is the class name in the above. cs file.

That's it. This will prevent the folder from being deleted AppDomain reboot, but will still reboot when modifying the web.config and Bin folders, which is exactly what we want.

But the deletion of several files will find that the session will still expire, why is this so? It's not clear yet ... So the search on the Internet has the following way

Configure the session to be saved under <system.web> as StateServer.

<sessionstate mode= "StateServer" statenetworktimeout= "20"
stateconnectionstring= "tcpip="/>

Using System.Reflection;
using System.Web;
Namespace Mywebsite
///stops tutorial the ASP tutorial. NET AppDomain being restarted (which C Lears
///Session state, cache etc.) whenever a folder is deleted.
public class Stopappdomainrestartonfolderdeletemodule:ihttpmodule
public void Init (HttpApplication context)
PropertyInfo p = typeof (HttpRuntime). GetProperty ("FileChangesMonitor",
Bi Ndingflags.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[] {});
public void Dispose () {}

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: 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.