Asp.net mvc 4 MVC4-发送HTTP标头后,服务器无法设置状态
从MVC3移动到MVC4后,该行Asp.net mvc 4 MVC4-发送HTTP标头后,服务器无法设置状态,asp.net-mvc-4,redirect,Asp.net Mvc 4,Redirect,从MVC3移动到MVC4后,该行 Return Redirect("https://secure.mysite.com/account/signup") 开始抛出异常 Server cannot set status after HTTP headers have been sent 这是本书的方法 Function signup() As ActionResult Dim HTTP_HOST = Request.ServerVariables("HTTP_HOST")
Return Redirect("https://secure.mysite.com/account/signup")
开始抛出异常
Server cannot set status after HTTP headers have been sent
这是本书的方法
Function signup() As ActionResult
Dim HTTP_HOST = Request.ServerVariables("HTTP_HOST")
If Request.IsSecureConnection = False Or HTTP_HOST <> "secure.mysite.com" Then
Return Redirect("https://secure.mysite.com/account/signup")
End If
'more code here
Return View(_viewModel)
End Function
函数signup()作为ActionResult
Dim HTTP\U HOST=Request.ServerVariables(“HTTP\U HOST”)
如果Request.IsSecureConnection=False或HTTP_主机“secure.mysite.com”,则
返回重定向(“https://secure.mysite.com/account/signup")
如果结束
'这里有更多代码
返回视图(_viewModel)
端函数
无法解决此问题,因为上面的返回重定向行是会话第一次被发回。我的代码中有一个类似的问题,我可以看到ELMAH日志:
System.Web.HttpException(0x80004005):发送HTTP头后,服务器无法设置状态。
我认为异常是因为Response.End和Response.Redirect不会导致MVC应用程序中的线程中止(Response.Redirect实际上不是MVC管道的一部分)
尝试:
我的代码中也有类似的问题,我可以看到ELMAH日志:
System.Web.HttpException(0x80004005):发送HTTP头后服务器无法设置状态。
我认为异常是因为Response.End和Response.Redirect不会导致MVC应用程序中的线程中止(Response.Redirect实际上不是MVC管道的一部分)
尝试:
return new RedirectResult("https://secure.mysite.com/account/signup", true);