IIS 7.5 URL Rewrite and 404 Not Found

iisrewrite

I'm trying to setup a reverse proxy using IIS to proxy request on port 80 to a local virtual machine on port 8080. The rewriting rule was setup using IIS GUI "Reverse Proxy" rule. However it work very strangely:

If there is a file/folder in the web folder (physical path), then the reverse proxy work. Otherwise, it throw 404 error.

For example, for a request to "http://example.com/myfile", if there is a file name "myapp" in the web folder then it get rewritten into "http://example.com:8080/myfile" properly. On the other hand, if there is no file "myfile" locally, then I get 404 error. It is as if there is something that check existence of a local file (and throw 404) before URL rewrite rules are processed.

I try disable some handles, re-order modules, and none seems to work 🙁

Running IIS 7.5 on Windows Server 2008 R2

Best Answer

If you have ASP.NET MVC application and get 404 error, this can be resolved by adding ignore path to routes.

routes.Ignore("path to ignore");

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.Ignore("api/controllerNmae/actionName");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}