Redirecting from site (Beta 2.0)

M

Mantorok

Hi

During certain periods I want all requests to my site to be redirected, the
only place I can see to do this is in the Session_Start event handler in the
global.asax file but when I try the following:

Session.Abandon();
Response.Redirect(http://www.site.com)

I get an error:

System.Web.HttpException: Session state has created a session id, but cannot
save it because the response was already flushed by the application.

at System.Web.SessionState.SessionIDManager.SaveSessionID(HttpContext
context, String id, Boolean& redirected, Boolean& cookieAdded)

at System.Web.SessionState.SessionStateModule.CreateSessionId()

at System.Web.SessionState.SessionStateModule.DelayedGetSessionId()

at System.Web.SessionState.SessionStateModule.OnReleaseState(Object source,
EventArgs eventArgs)

at System.Web.SessionState.SessionStateModule.OnEndRequest(Object source,
EventArgs eventArgs)

at
System.Web.HttpApplication.SyncEventExecutionStep.SystemWeb.HttpApplication.IExecutionStep.Execute()

at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)



Obviously I'm not approaching this the right way - any ideas?

Thanks

Kev
 
M

Mantorok

Tried that, now I'm getting this:

System.Web.HttpException: Session state has created a session id, but cannot
save it because the response was already flushed by the application.



Kev
 
A

Alexander Widera

have you other events in the global.asax?

Mantorok said:
Same.

Kev

System.Web.HttpApplication.SyncEventExecutionStep.SystemWeb.HttpApplicatio
n.IExecutionStep.Execute()
 
H

Hans Kesting

Mantorok said:
Hi

During certain periods I want all requests to my site to be
redirected, the only place I can see to do this is in the
Session_Start event handler in the global.asax file but when I try
the following:
Session.Abandon();
Response.Redirect(http://www.site.com)

I get an error:

System.Web.HttpException: Session state has created a session id, but
cannot save it because the response was already flushed by the
application.

Maybe you need here a
Response.Redirect(http://www.site.com, false);

Or else, don't use Session_Start, but Application_BeginRequest.

Are you sure you *need* that Session.Abandon()?

Hans Kesting
 
M

Mantorok

Hans Kesting said:
Maybe you need here a
Response.Redirect(http://www.site.com, false);

Or else, don't use Session_Start, but Application_BeginRequest.

Are you sure you *need* that Session.Abandon()?

In Beta 2 there is BeginRequest - that's why I'm pulling my hair out lol.

Kev
 
B

Bruce Barker

the default behavior of Response.Redirect is the write the redirct header,
then kill the thread. this is an easy way to stop page processing and the
html output it would generate. killing the thread in Session_Start is not a
good idea, because it too early in the page processing cycle.

you should Redirect(url,false), so the thread is not killed. you then have
to remenber this and stop page processing at a better time.

-- bruce (sqlwork.com)
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top