tags:

views:

353

answers:

2

Hi, 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;
            }

It prevents transcoders accessing o my site. but every now and then i get an error saying

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)

this only happens when i try to acces it via (for example) google transcoder but i want to understand whay it happens and how can i prevent it.

I have to abandon session so that on refresh user agent would re-eveluated

A: 

Have you tried flipping the order of abandoning your session vs redirecting?

Session.Abandon();
HttpContext.Current.Response.Redirect("/bannedBrowser.htm", true);
JustLoren
i've done this but it'll take time to see the result as i don't get error on every transcoder request
nLL
A: 

Have you seen this thread?

I encountered this exception (in a different context) and fixed it with the following ...

void Session_Start(object sender, EventArgs e) 
{
string id = Session.SessionID;
}
Robert Claypool
how would assiging sessionid to a string would help me? i don't need session id once i know it is a transcoder. I don't want to assign a session id once it is flushed as i need to check on next request if it is transcoder.
nLL