【发布时间】:2012-05-27 05:57:33
【问题描述】:
我正在尝试为网站实现 URL 重定向,而不是逐页进行。我想在 global.asax 文件中执行此操作。下面是我定义的代码。
我希望将http://website.net 作为我的主要网址,并且如果有人输入http://www.website.net,我希望有一个永久的网址重定向。
不幸的是,它不适用于实时网站。谁能指出代码中的问题。代码不会产生任何错误。
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://website.net"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://website.net", "http://www.website.net"));
}
}
【问题讨论】:
标签: asp.net redirect search-engine http-status-code-301