Pugal kannaN
Pugal kannaN

Reputation: 341

how to increase session timeout in asp.net?

I tried following codes to increase session timeout, but no use,

code is:

<sessionState mode="InProc" cookieless="true" timeout="60">
</sessionState>

Also code at

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session.Timeout = 15;
}

Upvotes: 24

Views: 97905

Answers (6)

Ibrahim Kanaan
Ibrahim Kanaan

Reputation: 21

<system.web>
  <authentication mode="Forms">
      <forms timeout="70"/>
  </authentication>
  <sessionState timeout="80"/>
</system.web>

It works for me, copy it to your web.config file.

Upvotes: 1

devi
devi

Reputation: 1

 <sessionState cookieless="false" timeout="30" mode="InProc"/>
  <authentication mode="Forms">
      <forms name="AppRootForms" loginUrl="LoginPage.aspx" protection="All" timeout="30" path="/" slidingExpiration="true"/>
    </authentication>
<system.webServer>
     <!--<max limit for storing session />-->
    <asp>
         <session allowSessionState="true" max="100000" timeout="00:30:00" />
    </asp>
</system.webServer>

Upvotes: 0

user8824275
user8824275

Reputation: 27

simply,go WebConfig,then set it,

        <system.web>
    <sessionState timeout="60"></sessionState>
  <compilation debug="true" targetFramework="4.0" />
</system.web>

Upvotes: 2

Ajay Prasad
Ajay Prasad

Reputation: 69

If you are using forms authentication then the default value of session timeout is 30min.Try this code to increase session timeout.

<system.web>
  <authentication mode="Forms">
      <forms timeout="70"/>
  </authentication>
  <sessionstate timeout="80"/>
</system.web>

I think the code help you.

Upvotes: 3

Worthy7
Worthy7

Reputation: 1561

I wanted to add my final solution. After reading that setting it in the config was "incorrect".

            if (model.RememberMe)
            {
                var ASPCookie = Request.Cookies["ASP.NET_SessionId"];
                ASPCookie.Expires = DateTime.Now.AddDays(15);
                Response.SetCookie(ASPCookie);
            }

Upvotes: 0

skywalker2909
skywalker2909

Reputation: 1686

You can increase the session time-out in asp.net in any one of the following ways

Using IIS Version 7 :

  1. Open up IIS
  2. Select your website from the list of sites
  3. Click on Session state on the right
  4. Now enter your session timeout under the cookie settings

OR

Web.config : Open up your web.config file and under the system.web section add the following :

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

Replace 20 with whatever number you wish.

OR

Global.asax file : Under the Session_Start method, set the timeout property of the session to the required value like this

Session.Timeout = "20";

Note : If you are setting a session timeout in both IIS as well as web.config, then the one in IIS will override the one in web.config

Hope this helps!

Upvotes: 38

Related Questions