[英]301 error and sample test
如何在 asp.net 中测试本地主机中的 301 错误。我添加了 global.asax 页面并编写了代码
void Application_BeginRequest(object sender, EventArgs e)
{
const string www = "http://www.localhost/test";
const string redirect = "http://localhost/test/";
string request = HttpContext.Current.Request.Url.ToString();
if (request.StartsWith(www, StringComparison.InvariantCultureIgnoreCase))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location",
redirect + request.Substring(www.Length));
}
}
并通过虚拟目录配置本地主机,但我无法看到我的配置有任何变化。
为什么不使用HttpResponse.RedirectPermanent()
代替? 它内置:
HttpContext.Current.Response.RedirectPermanent(redirectUrl);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.