.net Session state has created a session id but cannot save it because the response has already been dropped by the application
I have below in my global.asax Session_Start
string myBrowser = Utils.SafeUserAgent(Request);
foreach (string bannedbrowser in BrowserBan.BrowsersToBan)
{
if (myBrowser.IndexOf(bannedbrowser, StringComparison.OrdinalIgnoreCase) > -1)
{
HttpContext.Current.Response.Redirect("/bannedBrowser.htm");
Session.Abandon();
break;
}
This prevents access to the transcoder on my site. but every now and then I get the 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.ReleaseStateGetSessionID()
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.System.Web
.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
It only happens when I try to access it via (for example) Google Transcoder, but I want to understand why this is happening and how I can prevent it.
I need to drop the session so that the user agent is re-evaluated on upgrade.
+2
nLL
source
to share
2 answers
Have you seen this stream ?
I ran into this exception (in a different context) and fixed it like this:
void Session_Start(object sender, EventArgs e)
{
string id = Session.SessionID;
}
+4
Robert Claypool
source
to share
Have you tried to reverse the order of session abandonment or redirection?
Session.Abandon();
HttpContext.Current.Response.Redirect("/bannedBrowser.htm", true);
+2
JustLoren
source
to share