redirect to logon page after session timeout

Discussion in 'ASP .Net' started by francois, Apr 29, 2004.

  1. francois

    francois Guest


    I would like to redirect the user to the login page after the session time

    I tried to do a trick in the global.aspx.cs

    protected void Application_BeginRequest(Object sender, EventArgs e)


    object obj = Session["memberId"];

    if (obj == null)


    // do redirect



    But it says that the Session object cannot be called in that context.

    My goal is that I am trying to check at each request if the session object i
    stored in my Session is still existing or not. If not, it means the session
    is timed out and that i need to log in again and go back to the log in page.

    Thanks for any help

    francois, Apr 29, 2004
    1. Advertisements

  2. Try this:

    if(Session["memberID"] == null)


    Antoni Massó Mola, Apr 29, 2004
    1. Advertisements

  3. francois

    francois Guest

    the problem is that i cannot access the Session veriable in the
    Application_BeginRequest(Object sender, EventArgs e) method.

    When i run the project the Global.aspx does not compile and show an show
    the following error

    Exception Details: System.Web.HttpException: Session state is not available
    in this context.

    Line 55: protected void Application_BeginRequest(Object sender, EventArgs
    Line 56: {
    Line 57: if(Session["memberID"] == null)
    Line 58: {

    Then where can u do this check if i cannot do it in that method?


    francois, Apr 29, 2004
  4. francois


    May 20, 2010
    Likes Received:

    it is because you cannot access Session like that, try the following

    protected void Application_BeginRequest(Object sender, EventArgs e)
    HttpContext cntxt = default(HttpContext);
    cntxt = HttpContext.Current;

    if (cntxt.Session["SomeID"] == null)


    salmonriaz, May 20, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.