Server cannot set status after HTTP headers have been sent IIS7.5

后端 未结 10 879
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 12:32

Sometimes I get exception in my production environment:

  • Process information
    • Process ID: 3832
    • Pr
相关标签:
10条回答
  • 2020-11-27 12:50

    You are actually trying to redirect a page which has some response to throw. So first you keep the information you have throw in a buffer using response.buffer = true in beginning of the page and then flush it when required using response.flush this error will get fixed

    0 讨论(0)
  • 2020-11-27 12:51

    How about checking this before doing the redirect:

    if (!Response.IsRequestBeingRedirected)
    {
       //do the redirect
    }
    
    0 讨论(0)
  • 2020-11-27 13:00

    İf someone still having this problem.Try to use instead of ovverriding

     public void OnActionExecuting(ActionExecutingContext context)
        {
            try
            {
    
                if (!HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    if (!HttpContext.Current.Response.IsRequestBeingRedirected)
                    {
    
                        context.Result = new RedirectToRouteResult(
                    new RouteValueDictionary {  { "controller", "Login" }, { "action", "Index" } });
                    }
                }
    
            }
            catch (Exception ex)
            {
                   new RouteValueDictionary { { "controller", "Login" }, { "action", "Index" } });
            }
    
        }
    
    0 讨论(0)
  • 2020-11-27 13:04

    We were getting the same error - so this may be useful to some.

    For us the cause was super simple. An interface change confused an end user and they were pressing the back button in the browser at a 'bad' time after a form submission (sure we should probably have used a PRG pattern, but we didn't).

    We fixed the issue and the user is no longer pressing the back button. Problem solved.

    0 讨论(0)
提交回复
热议问题