This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19080|Reply: 3

[ASP.NET] ASP.NET StateServer that stores the Session

[Copy link]
Posted on 11/18/2017 9:20:15 PM | | | |

Since the company needs to load balance the server, the web project deploys one on each of the two front-end servers (web1 and web2). But sessions are used in projects. When you first land on web1, it is possible to jump from web1 to web2 because the load may increase after web1.
I found a lot of information from the Internet, and I also understand the configuration in web.config
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" timeout="30" cookieless="AutoDetect" />
Many examples on the Internet are stateConnectionString="tcpip=127.0.0.1:42424", which is of course fine on a web server, but when you change stateConnectionString to stateConnectionString="tcpip=192.168.1.82: 42424", there will be problems with both frontends. Microsoft did not give a specific solution, and the examples on MSDN also point to 127.0.0.1. Later, after researching and consulting experts, I realized that I had to modify the registry of the server that saves Sessin, here it is 192.168.1.82, and the modification is as follows:
Modify the registry:

HKEY_LOCAL_MACHINE"SYSTEM"CurrentControlSet"Services"aspnet_state"Parameters



AllowRemoteConnection=1



Then restart the ASP.NET State Service



The connection configuration is as follows:

<sessionState mode="StateServer"
stateConnectionString="tcpip=192.168.1.200:42424" cookieless="AutoDetect"
timeout="60" />

After that, it was OK after testing. Hope it helps others.
There is another problem that I still don't understand. The wap page I made will have the data stored in the ViewState on the page, and when the page is constantly refreshed, the data in it will be lost, and the time will never exceed 20 minutes. I don't know if it's a bug from Microsoft or what, this problem doesn't appear on web pages. Solution.
After a period of exploration, it is best to use less viewstate on the WAP page, and if the asp.net state service is enabled, then it is best to set cookieless to true, otherwise the session will be lost.




Previous:Simple package refactoring for Autofac Container
Next:Session states cannot be serialized. In "StateServer" or "SQLServer" mode...
 Landlord| Posted on 11/18/2017 9:21:34 PM |
ASP.NET session state module <Sessionstate>determines the four possible values of the tag in the Web.config file < the mode property of the tag under the System.web> tag: Off, Inproc StateServer, and SQLserver.    1 Inproc is the default setting
It allows "cookieless" sessions, as well as the storage of session data outside of the server. ASP.NET session state module is configured in the Web.config file as follows:
 Landlord| Posted on 2/26/2018 11:02:52 AM |
My own configuration


 Landlord| Posted on 7/10/2022 9:58:32 PM |
ASP.NET 4 now provides built-in support for compressing session data to store out-of-process sessions. To enable this feature, simply set compressionEnabledThe property is set to "true", as shown in the following code snippet:



ASP.NET will use the .NET Framework System.IO.Compression.GZipStream class to compress (and decompress) the session state.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com