global.asax redirect issue

  • Thread starter Thread starter wardy1975
  • Start date Start date
W

wardy1975

Hi all, got a bit of a strange one....I am developing in ASP.NET 2.0
and I have some code in my Session_Start method that sets user
attributes. If an error occurs at this time, such as the user is not
registered or configured for the site, I throw an error that is caught
by the Application_Error method of the global.asax file. I proceed to
get the last error information, clear it down, and then I attempt to
redirect to an error page using Response.Redirect. However, the
strange thing is that for some reason when I attempt to do this, it
results in the Session_Start being called again, which ends up putting
me in a loop as it throws the same error as before. Unfortunately I am
also integrated with CMS so using Server.Transfer is not necessarily an
option as it doesn't work right when transferring to a CMS page (which
one of our error pages is).

Has anyone ever seen this before or know why when doing a
Response.Redirect from with the Application_Error method would result
in Session_Start getting called? This type of behaviour does not occur
if the error happens anywhere else in the application or for any other
redirect that we have.

Thanks,
 
Sounds like the Session cookie it not being set properly since you Session_Start
is failing and when the user makes another request the server thinks it's
a new user. Change your code from Session_Start to some other location such
that it does lazy initialization. IOW, check to see if it's been called for
this user and if not call it and store a flag that you've called it.

-Brock
http://staff.develop.com/ballen
 
Back
Top