It was later found that if the deleted directory does not belong to the virtual directory where the current project is located, the session is available, but the session is not available; the prompt in the debug trace: Session.get_item (). returns null;
After the study found that the virtual directory to delete changes to the directory will cause session loss, so that the failure. and the essence of Session loss is: application Restart!
Here are a number of solutions:
1 Save session with external process
2 Save session with Database
3 The user ID is placed in a cookie, if the session is detected to be empty but the cookie exists in the reinitialization session.
4 The directory to be operated on will be removed from the ASP.net program
I use the first one here, the operation is as follows:
1. Start the ASP.net state service first, and the subsequent changes will not work if the service does not start.
2. Modify <sessionState/> configuration in Web.config as shown in the following code
Copy Code code as follows:
<sessionstate
Mode= "StateServer"
Stateconnectionstring= "tcpip=127.0.0.1:1314"
sqlconnectionstring= "Data source=127.0.0.1; Trusted_connection=yes "
Cookieless= "false"
Timeout= "40"
/>
Complete the above two points, even if the IIS restart, as long as the client browser is not changed, the session is also valid.
3. If the above settings are still invalid, you need to revise the registry:
[Hkey_local_machine\system\currentcontrolset\services\aspnet_state\parameters]
"Allowremoteconnection" =dword:00000001000
Note: If you want to store the object in session, add the [Serializable] property to the class, even if the object is serializable.