asp.net modifies and to remove Session lost after an in station directory operation

  • 2020-05-07 19:32:35
  • OfStack

Later, it was found that Session is available if the changed directory is not part of the virtual directory where the current project is located, and vice versa. Debugging trace: Session.get_item ()... Return null;
After a later study, it was found that deleting the changed directory in the virtual directory would cause Session to be lost and even become invalid. What session is missing is the essence: the application restarts!

There are several solutions:
1) save session with an external process
2) use database to save session
3) user ID puts cookie into it. If session is null but cookie exists, then re-initialize session.
4) remove the directory to be operated on from the asp.net program

I used the first one here, and the operation is as follows:
1. Start the "ASP.NET status service" first. If the service is not started, the following changes will not take effect.

2. Modified in Web.config < sessionState/ > The configuration is shown in the following code
 
<sessionState 
mode="StateServer" 
stateConnectionString="tcpip=127.0.0.1:1314" 
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" 
cookieless="false" 
timeout="40" 
/> 

After the above two points, even if IIS is restarted, session will still be valid as long as the client's browser markup has not changed.

3. If the above Settings are still invalid, the following registry needs to be modified:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters]
"AllowRemoteConnection"=dword:00000001000

Note: if you want to store an object in Session, you add the [Serializable] attribute to the class, even if the object is serializable.

Related articles: