Asp.net solution to session loss caused by Folder deletion

Source: Internet
Author: User

The simplest way is not to use the default method, that is
Inproc (default, In-process session status): sessions are stored in IIS processes (Web server memory ). If you are using Windows 2000 Server or Windows XP, iisuses the aspnet_wp.exe process. If you are using Windows 2003 server, iisuses w3wp.exe.

Inproc has the best performance. However, in-process sessions can easily lose session information. If the application is restartedProgramAll session information will be lost. Many causes may cause the restart of ASP. NET applications.
Modified the Web. config or global. asax file, or changed the modification date of the file.
Modified the files in the \ bin or \ app_code directory.
The anti-virus software modified the above files and so on.

You can consider the following two methods:
1. StateServer (off-process session status): the session is stored in the independent windowsservice process aspnet_state.exe.

To enable the session Status in StateServer, first enable ASP in Control Panel> Administrative Tools> services. net State services (Asp. and set this service to Automatic startup)

After starting the ASP. NET status service, you need to configure the ASP. NET application to use it.
Add the following content to the system. Web node in the web. config file:Code
<Sessionstate mode = "StateServer" statenetworktimeout = "20"
Stateconnectionstring = "TCPIP = Wagner. 0.0.1: 42424"/>
First, the mode attribute is set to StateServer. Next, the stateconnectionstring attribute is used to specify the location of the ASP. NET status server. The connection location is created at 127.0.0.1 and port 42424. Finally, the statenetworktimeout attribute is used to specify the connection timeout seconds.
Note that you must mark the object as serialized (use the serializable feature to mark the classes to be serialized) in order to store the object in the service. Microsoft recommends that all developers use the off-process session status during development to avoid site errors if the project is switched to an off-process provider or sqlserver.

Or use
2. sqlserver: the session is stored in the sqlserver database table. You can use aspnet_regsql.exe to configure it (sqlserver server)

Another method is to use the virtual directory of the producer:

The premise is that you have the permission to create a virtual directory under the web (project folder) site, and you can specify a virtual directory outside the web folder.

For example, if the app's upload folder is/uploadfiles, you need to create an uploadfiles virtual directory under the web site in IIS and point it to another folder outside the Web Folder.

And delete the physical directory of uploadfiles under the Web

In this way, you can bypass modifying the Web file structure and cause session loss. Deleting folders will not cause application process restart.

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.