在Asp.Net MVC中设定site路径所对应的默认action

设置路由的default的Controller和Action可以达到我们预期的效果,代码如下所示:

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

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

 

 

你可能感兴趣的:(asp.net)