Monday, 23 April 2012

Is it possible to set the session out time manually in ASP.NET? || How to set session timeout more than 20 min.? || How to set session timeout in web.config file?

Hi friends, in this article I will explain about Is it possible to set the session out time manually in ASP.NET? 
Yes we can set the session out time manually in web.config.
In ASP.NET we can set the session timeout in the web.config file.The code below set the session timeout to 30 minutes.

<system.web>
      <sessionState timeout="60"></sessionState>
    </system.web>                                              
                                                (or)
<system.web>
<sessionState mode="InProc" cookieless="false" timeout="30"/></system.web>

We can also give session timeouts for each page. The code for set the session for each page is as shown below.
In C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["MySession"] = "WELCOME";
        Session.Timeout = 1;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("default2.aspx");
    }

In VB.NET:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("Mysession") = "welcome"
        Session.Timeout = 1
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Redirect("default2.aspx")
    End Sub

"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook pageAspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter  on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on  RSSfeed Aspdotnet-Kishore for free updates directly to your Email inbox . Watch my blog  for more articles." 

No comments:

Post a Comment

© 2012-2014 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.