Set the Session Timeout Manually in ASP.NET

In this blog I will answer the question: Is it possible to set the session timeout manually in ASP.NET?

Yes, we can set the session timeout 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.

  1. <system.web>  
  2.     <sessionState timeout="60"></sessionState>  
  3. </system.web>  
or,
  1. <system.web>  
  2. <sessionState mode="InProc" cookieless="false" timeout="30"/></system.web>  
We can also give session timeouts for each page. The code for setting the session for each page is as shown below.

In C#
  1. protected void Page_Load(object sender, EventArgs e)   
  2. {  
  3.     Session["MySession"] = "WELCOME";  
  4.     Session.Timeout = 1;  
  5. }  
  6. protected void Button1_Click(object sender, EventArgs e)   
  7. {  
  8.     Response.Redirect("default2.aspx");  
  9. }
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now