[ASP] Session management is used to resolve session loss.

Source: Internet
Author: User

Using session management to resolve session loss issues steps

1. Enter the command in CMD

CD C:\Windows\Microsoft.NET\Framework\v4. 0.30319

Re-execute

Syntax: aspnet_regsql.exe-s server ip-u Database login-p database password-D to put the 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:

2. Check the database

Two tables are automatically added.

3. Adding code in Web. config

    <sqlconnectionstring= "server=.; database=zsz;uid=sa;pwd=123456 "  allowcustomsqldatabase=" true "  mode=" SQL Server "  timeout="></sessionstate  >

Test

Create a new HomeController to test from show () and Write (), one to show content from session and the other to insert content in session.

         PublicActionResult Show () {if(session["name"] !=NULL)            {                returnContent (session["name"].            ToString ()); }            returnContent ("NULL"); }         PublicActionResult Write () {if(session["name"] ==NULL) {session["name"] ="Wen"; }            returnContent ("OK"); }

After executing the Http://localhost:5451/home/write method

Observing database table changes

Now restart the debugger, open http://localhost:5451/home/show, you will find no need to re-assign the Session.

"Note" Do not close the browser while debugging.

Precautions

1. Do not directly double-click the use of Aspnet_regsql.exe to create, to directly use the steps in the command to generate, otherwise invalid.

If the operation is done through a visual interface, the resulting result is (see), inconsistent with the results of the command line generation.

2. If the validation session is successful, do not close your browser and restart debugging. Because the SessionId in the server and the cookie in the browser are correlated, once we close the browser, the information in the cookie may be emptied by default, and when opened again, the connection is re-established and the SESSIONID is reassigned. In other words, the previously saved SessionId has been invalidated and needs to be re-assigned to the Session.

[ASP] Session management is used to resolve session loss.

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.