Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying following code..but its not working....is it right way to check session timeout..plz help i am new to this..

//in global.asax
C#
protected void Session_Start(object sender, EventArgs e)
       {
           if (Context.Session != null)
           {
               if (Context.Session.IsNewSession)
               {
                   string sCookieHeader = Request.Headers["Cookie"];

                   if ((null != sCookieHeader) && (sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
                   {

                       HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);
                       UrlHelper urlHelper = new UrlHelper(new RequestContext(httpContext, new RouteData()));
                       string redirectUrl = urlHelper.Action("SessionExpire", "Home");

                       httpContext.RewritePath(redirectUrl);

                   }
               }
           }
       }

//web.config
<sessionstate mode="InProc" timeout="1">
Posted
Updated 11-Mar-14 21:43pm
v3
Comments
Ramug10 12-Mar-14 2:54am    
Did you set sessionstate in web.config?if yes what is your session mode??
Member 9579525 12-Mar-14 3:03am    
//web.config
<sessionstate mode="InProc" timeout="1">
Member 9579525 12-Mar-14 3:04am    
//web.config
<sessionstate moed="InProc" timeout="1">
Member 9579525 12-Mar-14 3:06am    
i have set mode to "InProc"

1 solution

Read this post to the end: Detecting Session Timeout in ASP.NET MVC 4[^]
 
Share this answer
 
Comments
Member 9579525 13-Mar-14 2:27am    
it works...but when session expires in partial view then that 'SessionExpire' view is displying only in partial view..

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



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