ASP.NET MVC Routing to start at html page

前端 未结 4 1784
自闭症患者
自闭症患者 2020-12-20 12:01

I am using IIS 6. I think my problem is that I don\'t know how to route to a non controller using the routes.MapRoute.

I have a url such as example.com and I want i

4条回答
  •  太阳男子
    2020-12-20 12:49

    The best solution is to remove the default Controller. You're running into this issue, because you're specifying both the default page and the default route without any parameters.

    By just removing the controller = "Home" on the route defaults, the / won't match the route anymore and because no other route will satisfy, IIS will look into the default documents.

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { action = "Index", id = "" }                       // Parameter defaults
        );
    }
    

提交回复
热议问题