[ASP. NET] [Session] uses SQLServer Session management to solve the Session loss problem. sessionsqlserver
Use SQLServer Session management to solve the Session loss problem
1. Execute the aspnet_regsql.exe program through the command line (do not double-click the installation), first enter the command in CMD
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
Run again
Syntax: aspnet_regsql.exe-S server ip-U database login name-P Database Password-d database-ssadd-sstype c
Example: aspnet_regsql.exe-S localhost-U sa-P 123456-d ZSZ-ssadd-sstype c
The result of successful execution is:
<SessionState sqlConnectionString = "server = .; database = ZSZ; uid = sa; pwd = 123456 "allowCustomSqlDatabase =" true "mode =" SQLServer "timeout =" 1000 "> </sessionState>
Public ActionResult Show () {if (Session ["name"]! = Null) {return Content (Session ["name"]. toString ();} return Content ("null");} public ActionResult Write () {if (Session ["name"] = null) {Session ["name"] = "wen";} return Content ("OK ");}
After the http: // localhost: 5451/home/write method is executed
If the operation is performed on the visual interface, the generated result is (SEE), which is inconsistent with the result generated by the command line.
2. When verifying whether the session status is successful, do not close the browser and restart debugging. Because the SessionId in the server is associated with the Cookie in the browser, once we close the browser, the information in the Cookie may be cleared by default, A new connection is established with the server and SessionId is re-allocated. That is to say, the SessionId that was previously saved to the database has expired and you need to assign a new value to the Session.