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.
- <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 setting 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");
- }