HttpException after Session Timeout

R

Rolf Gossen

Hello NG,

In my Web-Application I want to redirect the User to the Login-Page
whenever his Session has timed out. According to a lot of NewsGroup
Entries this can be achieved by the following code in global.asax

public Global()
{
InitializeComponent();
this.PreRequestHandlerExecute += new System.EventHandler
this.OnPreRequest);
}

protected void Session_Start(Object sender, EventArgs e)
{
Session["NeedsLogin"] = true;
}

protected void OnPreRequest(object sender, System.EventArgs evt)
{
if ((bool) Session["NeedsLogin"] == true)
Server.Transfer ("login.aspx");
}


Hence I face the following problem. Whenever my Session times out I
get the following HttpException.

HttpException (0x80004005):
Der Anzeigestatus für diese Seite ist ungültig, da er möglicherweise
beschädigt wurde.]

The Text is german and can be translated to : "invalid viewstate page
has possibly been damaged"

All pages are initialized with <%@ Page ... enableSessionState="true"
%>

Can anyone help me
Rolf
 
H

Hans Kesting

Rolf Gossen said:
Hello NG,

In my Web-Application I want to redirect the User to the Login-Page
whenever his Session has timed out. According to a lot of NewsGroup
Entries this can be achieved by the following code in global.asax ....

protected void OnPreRequest(object sender, System.EventArgs evt)
{
if ((bool) Session["NeedsLogin"] == true)
Server.Transfer ("login.aspx");
}


Hence I face the following problem. Whenever my Session times out I
get the following HttpException.
....

"invalid viewstate page has possibly been damaged"
...

Can anyone help me
Rolf

The problem is not the session timeout, but the server.transfer.
The viewstate is marked by the page that has generated it. When you
transfer to a different page (login.aspx) the stored originating page
is not equal to the current page and this is the reason for the errormessage.

Two possible solutions:
- simply change Server.Transfer to Response.Redirect
- set enableViewStateMac to false (in the @page directive in your login.aspx)

Hans Kesting
 
R

Rolf Gossen

Two possible solutions:
- simply change Server.Transfer to Response.Redirect
- set enableViewStateMac to false (in the @page directive in your login.aspx)

Hans Kesting


Thanks a lot it works fine.
But...
It is only the second solution that works. I don't bother since I only
need one working solution.

Rolf
 

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