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

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

Sometimes I get exception in my production environment:

  • Process information
    • Process ID: 3832
    • Pr
10条回答
  •  伪装坚强ぢ
    2020-11-27 12:44

    I had the same issue with setting StatusCode and then Response.End in HandleUnauthorizedRequest method of AuthorizeAttribute

    var ctx = filterContext.HttpContext;
    ctx.Response.StatusCode = (int)HttpStatusCode.Forbidden;
    ctx.Response.End();
    

    If you are using .NET 4.5+, add this line before Response.StatusCode

    filterContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
    

    If you are using .NET 4.0, try SuppressFormsAuthenticationRedirectModule.

提交回复
热议问题