我有一個HttpModule在ASP.NET WebForms應用程序中重定向某個URL:s。它可以在我的機器上使用ASP.NET開發服務器。但是當我用IIS7將它上傳到我們的Win2k8服務器時,它似乎沒有任何反應。我已將<add name="Test.Web" type="Test.Web.Core.HttpModules.RedirectOldUrls, Test.Web" />
放入system.webServer/modules部分,並且在inetmgr中我可以看到其他模塊。在我上傳代碼之前和之後,該網站似乎都以相同的方式運行,而不應該這樣做。在IIS7中無法使用的HttpModule
經過編輯的代碼示例:
public void Init(HttpApplication context)
{
context.Error += PageNotFoundHandler;
}
public static void PageNotFoundHandler(object sender, EventArgs evt)
{
Exception lastErrorFromServer = HttpContext.Current.Server.GetLastError();
if (lastErrorFromServer != null)
{
RedirectToNewUrlIfApplicable();
}
}
private static void RedirectToNewUrlIfApplicable()
{
string redirectUrl = GetRedirectUrl();
if (!string.IsNullOrEmpty(redirectUrl))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", redirectUrl);
}
}
private static string GetRedirectUrl()
{
return RedirectableUrls.GetUrl();
}
是的,我確實把它放在那裏,但忘了寫在這裏。不管怎麼說,還是要謝謝你。 – 2010-02-15 17:30:13
只是問清楚,並100%肯定: 你把它放在System.Web或System.webServer? – 2010-02-15 18:52:41
system.webServer,我可以在IIS7的模塊管理器中看到它,所以它顯示出來。但它沒有做任何工作。 – 2010-02-15 19:02:27