global.asax redirect issue

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,
 
B

Brock Allen

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.
 

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

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top