[ASP. NET] [Session] uses SQLServer Session management to solve the Session loss problem. sessionsqlserver

Source: Internet
Author: User

[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.

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.