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
 
Joined
May 20, 2010
Messages
1
Reaction score
0
Session

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

cntxt.Response.Redirect("redirectpage.aspx");

}
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top