我需要为某些页面执行301重定向,并在application_beginRequest()中的global.asax中添加了代码。它在我的本地机器上工作正常。当我在实时服务器上更新站点的DLL时,它不起作用。有任何想法吗?它可能是IIS服务器配置吗?
我在本地使用VS2012和Asp.Net Webforms 3.5 Framework。
protected void Application_BeginRequest(object sender, EventArgs e)
{
string path = HttpContext.Current.Request.Url.AbsolutePath;
if (path.EndsWith(".xml") || !path.Contains("."))
{
RedirectOldPages(path);
}
}
private void RedirectOldPages(string path)
{
//PagesToBeRedirected is a static class with a dictionary in it
if (PagesToBeRedirected.RedirectPages.ContainsKey(path))
{
//301 Permanent Redirect Page
Response.Redirect(PagesToBeRedirected.RedirectPages[path], false);
Response.StatusCode = (int)HttpStatusCode.MovedPermanently;
CompleteRequest();
}
}