Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Redirect the user to login page after a period of inactivity or when the session expires.
Posted
Updated 26-Jul-12 23:41pm
v2

Hi,
Usually, you set the session timeout, and you can additionally add a page header to automatically redirect the current page to a page where you clear the session right before the session timeout.

From http://aspalliance.com/1621_Implementing_a_Session_Timeout_Page_in_ASPNET.2[^]

C#
namespace SessionExpirePage
{
    public partial class Secure : System.Web.UI.MasterPage
    {
        public int SessionLengthMinutes
        {
            get { return Session.Timeout; }
        }
        public string SessionExpireDestinationUrl
        {
            get { return "/SessionExpired.aspx"; }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            this.PageHead.Controls.Add(new LiteralControl(
                String.Format("<meta http-equiv='refresh' content='{0};url={1}'>", 
                SessionLengthMinutes*60, SessionExpireDestinationUrl)));
        }
    }
}


The SessionExpireDestinationUrl should link to a page where you clear the session and any other user data.

When the refresh header expires, it will automatically redirect them to that page.

Here[^] is a video, you must watch that.

Also check the following:
http://csharpdotnetfreak.blogspot.com/2008/11/detecting-session-timeout-and-redirect.html[^]
http://forums.asp.net/p/1299988/2533830.aspx[^]



--Amit
 
Share this answer
 
Try This...

check session on evry page and add in Web.config above the page tag.

<sessionstate timeout="5" mode="InProc"></sessionstate>


it redirect to homepage when user is idle for 5 minutes.


if any query ,please post it.
 
Share this answer
 
Is Google[^] broken at your place? It returned about 225,000 results (0.42 seconds) for your query.
Top Results:

redirect-to-login-page-on-session[^]
redirect-to-login-page-on-session-expiration-asp-net[^]
 
Share this answer
 

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