locked
Session in asp.net RRS feed

  • Question

  • User-2045686240 posted

    Hai,

             can u pls tell me how to maintain the session until the user sign out.Session Expires in 20 seconds.but i want to maintain the session?

            thanks in advance

     

    Wednesday, September 28, 2011 5:10 AM

Answers

All replies

  • User-573138384 posted

    I am afraid it shouldn't be 20 seconds. Check web.config sessionState element. What is the timeout value of this element? This value is in minutes. So set whatever the value you want not to expire the session.

    <sessionState  timeout="60"...

    But the default session timeout 20 mins sounds good compare to high timeout value. Because it eats up your memory...

    Wednesday, September 28, 2011 5:24 AM
  • User-1971614856 posted

    Write following statement in Sysetm.Web section of your Web.Config file

    <sessionState timeout="30"/>

    This will increase Session time upto 30 Minutes.

    Wednesday, September 28, 2011 5:24 AM
  • User-625475160 posted

    hi,

    in web config file check the session timeout value and change the value what u want.

    <sessionState mode="InProc" timeout="30"></sessionState>

    in that timeout value set the value u want.

    Wednesday, September 28, 2011 6:00 AM
  • User-1867048303 posted

    Hi,
    Session default timeout is 20 minutes.
    But if you want to change it then write this one in web.config.

    <sessionState timeout="40"></sessionState>

    Wednesday, September 28, 2011 6:05 AM
  • User-1103477405 posted

    The default session timeout for an ASP.NET application is 20 mins. You can change the web.config to increase the time out value.

    But I see your requirement as not to expire the uer session until the user does signout on his own.I don't know the context of your requirement . But for the session to maintain indefinitely until the user does signout ,just do a post back operation for every 15 mins as follows

     

    Add the following in the master page of the application

    // Add in the page load event
    if (!Page.ClientScript.IsStartupScriptRegistered("URLs"))
    {
          string KeepAliveURL = String.Format("<input type='hidden' id='hdnKeepAliveURL' value={0} />", "KeepAlive.aspx");
          Page.ClientScript.RegisterStartupScript(this.GetType(),"URLs", KeepAliveURL,false);
    }

     //KeepAlive.aspx is a dummy page in the application

    <script type="text/javascript">

           function sessionKeepAlive() {       
               var webRequest = new Sys.Net.WebRequest();
               webRequest.set_url(document.getElementById('hdnKeepAliveURL').value);
               webRequest.invoke();          
               setTimeout("sessionKeepAlive()",900000); //calls sessionKeepAlive every 900000 milli seconds(15 mins)
           }
    </script>

    Call sessionKeepAlive() in <body> onload() event of the page

    As your default session timeout is 20 mins , do the post back every 15 mins to keep the session alive

    Note: If the user closes the browser without doing signout ,the session is automatically killed within 20 mins as no post backs happen to keep session alive.

     

    Wednesday, September 28, 2011 9:34 AM
  • User-2045686240 posted

    Hai TMK555,

                        u have mentioned in the above forum if (!Page.ClientScript.IsStartupScriptRegistered("URLs")).

                       In the Place of URL what i have to give?Can u pls tell me clearly?

    Friday, September 30, 2011 3:41 AM
  • User1788860904 posted

    From TMK555, if (!Page.ClientScript.IsStartupScriptRegistered("URLs")). <-- URLs is the script key.

    Friday, September 30, 2011 6:14 AM
  • User1613327603 posted

    set session timeout

    or

    you do post back after every some time.

    you can see in this page :  "http://forums.asp.net/" this page dopostback after every some times

    Friday, September 30, 2011 8:43 AM
  • User-1103477405 posted

    Hai TMK555,

                        u have mentioned in the above forum if (!Page.ClientScript.IsStartupScriptRegistered("URLs")).

                       In the Place of URL what i have to give?Can u pls tell me clearly?

    URLs   -> it is the script key. You can use any name you want 

     

    Friday, September 30, 2011 9:17 AM
  • User-2103114970 posted

    Hi,

    you have to change in IIS and web.config

    follow like below link it will work

    http://forums.asp.net/t/1283350.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 30, 2011 11:33 AM