How to redirect to login page automatically, after session time out.

    Question by:


    How to redirect to login page automatically, after session time out?
    In my web application, user logs in in the application, after a certain time (30 mins) session times out and login page appears only AFTER user action.
    I would like to redirect the user back to the login screen automatically (before user performs any action) after session has timed out.

    Your suggestions will be greatly appreciated.

    I used following code in pagerender of masterpage.
     HttpContext.Current.Response.AppendHeader("Refresh", Convert.ToString(((HttpContext.Current.Session.Timeout * 60) - 5)) + "; Url=homepage.aspx")
    Also, i have Session_Start/Session_end in global.asax.

    Select allOpen in new window

    Good Question?

    Verified Answer?

    The member who asked this question verified this comment provided the solution that solved their problem.

    by:Posted on 2008-05-14 at 05:49:36ID: 21563505

    function timeout(){window.location = ""}

    call it in your html:
    <body onload="setTimeout('timeout()', 5000)">

    But you would still have to put this into every page... not sure how you are going to accomplish this without masterpages.

    This content is available to Experts Exchange members

    See the answer now
    with your Free 30 Day Trial

    Get unlimited access to solutions & experts

    • 4,169,477 solved questions
    • 3,805 articles & videos
    • 15,413 tech experts

    Get Access Now

    Ask Your Tech Question. Get Expert Solutions.We will email you when an expert has commented on your question.

    We will never share this with anyone. Privacy Policy Terms of Use

    Select topics

    You may select up to five topics.

    Top Expert Contributor

    Essential articles and videos from the Experts

    More valuable questions with Expert answers


    RELATED TOPICS view all topics

    1. ASP.NET
    2. C#
    3. Visual Basic.NET
    4. MS Development
    5. Editors IDEs
    6. Visual Basic Classic
    7. MS SQL Server
    8. MS SQL Server 2005
    9. Programming
    10. JavaScript