Mixing ASP.NET and MVC routing

Here is the solution I settled on. I installed the NuGet Microsoft.AspNet.FriendlyUrls package. Then I named the .aspx page with a page name that would look good without the extension. Then I set up the routing as follows:


    public static void RegisterRoutes(RouteCollection routes)
    {
        FriendlyUrlSettings aspxSettings = new FriendlyUrlSettings();
        aspxSettings.AutoRedirectMode = RedirectMode.Off;  // default=Off
        routes.EnableFriendlyUrls(aspxSettings);

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

        routes.MapPageRoute("Design-Fancy", "Design/Fancy/{*queryvalues}", "~/Design/Fancy.aspx", true);
        routes.MapPageRoute("Design-Simple", "Design/Simple/{*queryvalues}", "~/Design/Simple.aspx", true);
    } 
posted @ 2016-08-04 22:51  shiningrise  阅读(215)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css