redirect to logon page after session timeout

F

francois

Hi,

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

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
 
A

Antoni Massó Mola

Try this:

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

Response.Redirect("redirectpage.aspx");

}
 
F

francois

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
e)
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

Antoni Massó Mola said:
Try this:

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

Response.Redirect("redirectpage.aspx");

}

francois said:
Hi,

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

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top