|
Forums » .NET » ASP.NET »
|
If session exipres i have to redict session exipres page. |
Posted Date: 22 Sep 2012 Posted By:: suneel Member Level: Silver Member Rank: 488 Points: 5
Responses:
7
|
I a m writing below code in global.ascx file. But it is not working. If session exipres i have to redirect automaticalyy session exipres page.
void Session_Start(object sender, EventArgs e) { //// Code that runs when a new session is started if ((Context.Session != null)) { if (Session.IsNewSession) { string strCookieHeader = Request.Headers["Cookie"]; if ((strCookieHeader != null)) { if (strCookieHeader.ToUpper().IndexOf("ASP.NET_SESSIONID") >= 0) { //On timeouts, redirect user to timeout page. // Response.Redirect("Default.aspx"); //Server.Transfer("Default.aspx"); Response.AppendHeader("Refresh", "\"" + Session.Timeout.ToString() + ";url=/Your-Session-Is-Expired.aspx"); } } } }
}
In Web.config file <sessionState mode="InProc" cookieless="true" timeout="2"/>
but it is not working.Could please help me.
|
Responses
|
#689338 Author: Ravindran Member Level: Diamond Member Rank: 3 Date: 22/Sep/2012 Rating:  Points: 3 | Suneel,
Write below code in the page_load event to redirect to session timeout page when session is empty
if (Session["user"] == null) { Response.Redirect("SessionTimeOut.aspx"); }
other option Write one common method in class file with above code and call in each page that method in page load event
Regards N.Ravindran Your Hard work never fails
| #689345 Author: Asheej T K Member Level: Diamond Member Rank: 2 Date: 22/Sep/2012 Rating:  Points: 3 | Hi,
Check session in each page before displaying,
if (Session["UserInfo"] == null) { Response.Redirect("Login.aspx"); }
While logging out clear abandon the session
session.Abandon();
Also disable browser Back button using below code,
<script type = "text/javascript" > function disableBackButton() { window.history.forward(); } setTimeout("disableBackButton()", 0); </script>
Regards, Asheej T K Microsoft MVP[ASP.NET/IIS] DotNetSpider MVM
Dotnet Galaxy
| #689353 Author: Laxmikant Member Level: Gold Member Rank: 167 Date: 22/Sep/2012 Rating:  Points: 2 | First check the web.config file settings. You need to check the session mode attribute and timeout setting for this.
| #689354 Author: suneel Member Level: Silver Member Rank: 488 Date: 22/Sep/2012 Rating:  Points: 1 | In Web.config file <sessionState mode="InProc" cookieless="true" timeout="2"/> i taken like this in web config file. That we can able to write that code in gloabal.acsx file. we have to write in all the page loade event only
| #689399 Author: Anil Kumar Pandey Member Level: Platinum Member Rank: 1 Date: 23/Sep/2012 Rating:  Points: 2 | In the page load please check the Session value so if at any point of time the session value is expired you will be redirect to a Time out page.
if (Convert.ToString(Session["user"]) == "") { Response.Redirect("SessionTimeOut.aspx"); }
Thanks & Regards Anil Kumar Pandey Microsoft MVP, DNS MVM
| #689433 Author: Alwyn Duraisingh Member Level: Gold Member Rank: 11 Date: 24/Sep/2012 Rating:  Points: 2 | You can catch the event in the Session_End in global.asax file, You can trap the session value and can redirect to the login page or you can have a custom page and prompt the user from activating the session.
Also you can increase the session value in this event
Regards, Alwyn Duraisingh.M << Database Administrator >> Jesus saves! The rest of us better make backups...
| #689436 Author: suneel Member Level: Silver Member Rank: 488 Date: 24/Sep/2012 Rating:  Points: 1 | Hi Alwyn Duraisingh, How we can actch we can redriect that login page.. could please tell me....
|
|
| Post Reply |
|
|
|
You must Sign In to post a response.
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|