Asp.net 我能';t解决未绑定的异常:无法在已设置HTTP头之后设置状态
我有一个在Asp.net 我能';t解决未绑定的异常:无法在已设置HTTP头之后设置状态,asp.net,asp.net-mvc,asp.net-mvc-4,exception-handling,http-headers,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Exception Handling,Http Headers,我有一个在IIS中发出警告的应用程序 当我在我的visualstudio中尝试它时,没有任何错误。 我在global.asax中执行了一个Application\u错误,以捕获未受影响的异常 以下是有关此错误的信息: Message: Server cannot set status after HTTP headers have been sent. Source: System.Web. InnerException: (none) End of stacktrace: at S
IIS
中发出警告的应用程序
当我在我的visualstudio
中尝试它时,没有任何错误。
我在global.asax
中执行了一个Application\u错误
,以捕获未受影响的异常
以下是有关此错误的信息:
Message: Server cannot set status after HTTP headers have been sent.
Source: System.Web.
InnerException: (none)
End of stacktrace:
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
即使在调用
Response.Redirect
和RedirectToAction
时,操作方法仍会被触发
要解决此问题,请将重定向行更改为
filterContext.Result = RedirectToAction("index", "error");
及
请发布引发错误的实际代码。通常这是由在返回操作之前手动调用HttpContext.Current.Response.End()或HttpContext.Current.Response.Redirect()引起的。尝试将重定向放入action@Alexander:好的,谢谢,我已经添加了我希望生成错误的代码段@Wettt:好的,谢谢,但这是不可能的,因为方法的定义(void OnActionExecuting(…))好的,谢谢,看起来它解决了我的部分问题。仍然有错误,但我做了一个大的IF子句来直接重定向应用程序!谢谢
filterContext.Result = RedirectToAction("index", "error");
filterContext.Result = Redirect(ConfigManager.AuthService);