Doing a simple timeout page with WebClientApplication

<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %>
<script Language="C#" RunAt="Server">

protected override void PrePageExecute(Page page)
{
// True when the current session was recreated with the current request
if (Session.IsNewSession)
{
// redirect if the requested page is not Default or the Timeout page
// or if the request method isn't GET
if ((!(page is Retail.Web._Default) &&
!(page is Retail.Web.Errors.Timeout)) ||
Request.HttpMethod != "GET")
{
Response.Redirect("~/Errors/Timeout.aspx");
return;
}
}
base.PrePageExecute(page);
}
 



This approach relies on the Session.IsNewSession property to tell us if the current session was created with the current request, with a bit of convenience support for the timeout/default pages.


Nikhil has a more detailed solution: Detecting Session Timeout in ASP.NET 2.0 Web Applications if you want to differentiate between



  • new session object and user was really new, (aka no ASP.NET_SessionId)

vs



  • new session object and the user really timed out (aka sorry I was surfing the web and the app timed out)