[英]ASP.NET 3.5, googlebot, 301 Redirect “Cannot redirect after HTTP headers have been sent”
[英]ASP.NET MVC Cannot redirect after HTTP headers
我在 IIS 中收到此警告,它是否与从浏览器请求 cookies 或我如何使用Response.Redirect
有关? 从一些研究中,我看到我需要添加Response.Buffer = true;
的建议。 那是对的吗?
代码
public ActionResult GetTemplateById(string TemplateId)
{
string loginUrl = ConfigurationManager.AppSettings["loginUrlCottTemplateId"];
Request.Cookies.Add(new HttpCookie("ev", "sJlp+HNulad4GaX2RCjjlQ=="));
if (Request.Cookies["customerguid"] != null)
{
HttpCookie cookie = Request.Cookies["customerguid"];
string cookieValue = cookie.Value;
cookieValue = cookieValue.Replace("%2D", "-");
}
else
{
Response.Redirect(loginUrl + TemplateId);
}
if (!AuthenticationRep.IsUserValid(Request))
{
return Redirect(storeProductLink);
}
var memoryStream = new System.IO.MemoryStream(fm.FileData);
return new FileStreamResult(memoryStream, "application/pdf");
}
IIS 异常
异常消息:发送 HTTP 标头后无法重定向。
线程信息:
线程 ID:213
线程账号名:IIS APPPOOL.NET v4.5
是否冒充:假堆栈跟踪:
在 System.Web.HttpResponse.Redirect(字符串 url,Boolean endResponse,Z27245B5Z4F永久)
在您的 ASP.NET MVC 应用程序中,您使用Response.Redirect(someurl)
进行重定向。
在 ASP.NET Web Forms 应用程序中使用时,从不执行Response.Redirect(someurl)
之后的任何代码。 但是,当您在 ASP.NET MVC 中使用相同的代码时,即使在发送重定向响应之后,代码执行也会继续。 要知道为什么,go 通过这个。
您的代码试图在同一个 ActionResult 中重定向两次,通过 -
Response.Redirect(loginUrl + TemplateId);
和
return Redirect(storeProductLink);
我相信这是抛出这个错误。
请更改Response.Redirect(loginUrl + TemplateId)
以return Redirect(loginUrl + TemplateId)
并检查这是否解决了您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.