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);
    } 
原文地址:https://www.cnblogs.com/shiningrise/p/5738707.html