. NET Session Timeout control

Source: Internet
Author: User

Webconfig Set the timeout is a big value, but the validity of the session is still not maintained for an hour.

Check, mainly said mode= "InProc" words, session is placed in the process, so the most easily lost.  If placed in services and databases, it will stabilize. Do a lot of people put in the service?

Is it necessary to set cookieless to true?

http://blog.csdn.net/kaifa123/article/details/6890106


==============================================================

. NET Session Timeout control

http://blog.csdn.net/freeman127/article/details/8633449

After discovering that the <sessionstate mode= "InProc" timeout= "></sessionState>" is added directly to the Web. config file, the session will soon expire, After checking the information on the Internet, the following code can be used to control the session timeout length effectively:

<sessionstate mode= "StateServer" stateconnectionstring= "tcpip=127.0.0.1:42424" cookieless = "false" timeout= "240" statenetworktimeout= "14400" ></sessionState>

Plus, you'll need to open services on the server where the site is located,--asp.net State Service is set to start, and then automatically. Property Options Description
mode specifies where the session state is stored.
OFF indicates that session state is not enabled.
InProc indicates that session state is stored locally.
StateServer indicates that session state is stored on the remote computer.
SQL Server indicates that the session state is stored on a. ========================================================================http://wenwen.sogou.com/z/q209179334.htm
The default timeout for the session is 20 minutes, and the page will time out without action for 20 minutes. It can be webconfig and modified in the inside.
Ask:

I've set it to 60 minutes, even though the default is 20 minutes, and sometimes it's not a few minutes.

Reply:

Solution for ASP. NET session Timeout Collection The first method:

I have a good idea. And always use it, it feels so cool.

1, in the Web. config add: <sessionstate mode= "StateServer" stateconnectionstring= "tcpip=127.0.0.1:42424" cookieless = " False "timeout=" statenetworktimeout= "14400" ></sessionState>

2, click on the lower left corner of the computer, run the input services.msc enter to find the ASP. NET state Service, double-click, change to Automatic, and enable.

Where statenetworktimeout the connection between the client and the server for a long period of time without transmitting information. I set the 14400, that is: 14400/60/60=4 hours

Disadvantage: The session is stored in the server with the ASP. can cause strain on server resources. If you have money, you'd better buy a server dedicated to session services. Of course, it doesn't matter for small applications. Have done a small log system, log, as implies meaning, is the long-term open web page, something to the above record, running for a year, not because the session has been a problem.

Second approach (recommended):

1) Create a file savesession.js (Xhbmj:js better rewrite to support more browsers, with jquery best) function createxmlhttprequest () {      VAR xmlhttp;          try{         xmlhttp = New ActiveXObject ("Msxml2.xmlhttp"); IE 5.0 version     }      catch (e) {          try{             xmlhttp = new ActiveXObject (" Microsoft.XMLHTTP "); IE 5.5 version         }          catch (e) {             try{                  xmlhttp = new XMLHttpRequest (); Browsers that do not support ActiveX space             }               catch (e) {}         }     }      return XMLHTTP; }

Function Reconnect () {var url= ' reconnect.aspx ' Xmlhttp=createxmlhttprequest () xmlhttp.open (' GET ', url, True) Xmlhttp.send (NULL)//requires only contact with the server and does not require return data, therefore, no return processing}

function Refreshme () {setinterval ("reconnect ();", 60000);//This time adjusted according to the actual situation}

2) Add <script language= "JavaScript" src= "Savesession.js" ></script> on the page that needs to maintain session, in <body> Inside add onload= "Refreshme ();" 3) Create a reconnect.aspx page that can have no content for any. aspx pages.

A third approach: self-creation

Create an empty page, set the page to automatically refresh, you can use the timing of the HTML refresh, CS file to write something like:

String str = session["LoginID"]. ToString ();//preferably a judgment null

Embed this page as an IFRAME in a long-acting page, setting the width of the iframe to be 0

Ask:

The first approach is yes, you have a server that is typically configured like this.

=====================================================================

http://bbs.csdn.net/topics/60464405http://bbs.csdn.net/topics/40269870

. NET Session Timeout control

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.