user147215
user147215

Reputation:

Gloabl.asax Context.RewritePath IIS 7.5

The following code-snippet works fine when I run it in debug mode, but throws a 404 when I run it through IIS (7.5)

Is there a web.config setting I need to add for IIS?

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));
            }
        }
    }

Upvotes: 2

Views: 1219

Answers (1)

SLaks
SLaks

Reputation: 887777

You need to add <modules runAllManagedModulesForAllRequests="true"> in <system.WebServer> in Web.config.

Upvotes: 2

Related Questions