Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

how to set Session expiring after 20 minutes and redirect to home page automatically.
Posted
Comments
Richard C Bishop 30-Oct-13 11:04am    
You will need to write a redirect line of code in the On_SessionEnd event in the Global.asax page of your project. The Session time out can be set in the web.config. Also, you must set the session state to "InProc" in order the Global.asax to run the code.

1 solution

C#
Session.Timeout = 20;


C#
if (Session["yourSessionname"] == null)
     {
         Response.Redirect("http://www.google.com");
     }



if you write your code inside of class
C#
if (HttpContext.Current.Session["SessionName"] == null)
      {
          Response.Redirect("http://www.google.com");

      }



and also u can use this in the web.config

XML
<system.web>
   <sessionState timeout="2"></sessionState>
 
Share this answer
 
v3
Comments
Ranjan.D 30-Oct-13 11:17am    
Sorry this would be a temporary solution and it's not really a good one because imagine one has to add these lines of code in every page.
seyed mahmud shahrokni 30-Oct-13 11:21am    
go and take a nap baby !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900