Here's the attribute:
public class CheckSessionAttribute : ActionFilterAttribute
{
public override void OnActionExecuting( ActionExecutingContext filterContext )
{
if ( filterContext.HttpContext.Session.IsNewSession )
{
FormsAuthentication.SignOut();
filterContext.Controller.TempData[Constants .TEMPDATA_KEYS .TIMEOUT] = "Your session has timed out. Please login again to continue." ;
filterContext.Result = new RedirectResult ( "/" );
}
}
}
Now you need only check the presence of that TempData key on your logon view in order to show a proper timeout message instead of the standard login message.
Note the use of RedirectResult. The old Response.Redirect will do a proper redirect, but won't terminate the original request (even with the overload containing the parameter that tells it to do so). Response.Redirect should really raise an error when used in an MVC app.