Global.asax Context.RewritePath IIS 7.5

时间:2011-02-07 18:48:38

标签: url-rewriting global-asax

以下代码片段在调试模式下运行时工作正常,但在通过IIS运行时抛出404(7.5)

我是否需要为IIS添加web.config设置?

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        string currentUrl = Request.Url.ToString();
        List<string> pages = new List<string>();
        pages.Add("/about-us.html");
        pages.Add("/services");

        foreach (string page in pages )
        {
            if (currentUrl.Contains(page))
            {
                Context.RewritePath(string.Format("/page.aspx?page={0}", page));
            }
        }
    }

1 个答案:

答案 0 :(得分:2)

您需要在{。1}}中添加<modules runAllManagedModulesForAllRequests="true">在Web.config中。