zoukankan      html  css  js  c++  java
  • mvc 路由伪静态实现

    很多网站都采用伪静态,例如以html、shtml等结尾的url,mvc的路由可以轻松实现。

    配置路由

    默认路由配置

    添加伪静态路由

    mvc的路由原理是从上往下匹配的,所以只需要在后面添加自己配置的路由即可

     public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
                routes.MapRoute(
                    name: "Default1",
                    url: "{controller}/{action}/{id}/{page}.html",
                    defaults: new { controller = "Home", action = "Index" }
                );
    
                routes.MapRoute(
                     name: "Default2",
                     url: "{controller}/{action}.html",
                     defaults: new { controller = "Home", action = "Index" }
                 );
    
                routes.MapRoute(
                    name: "Default3",
                    url: "{controller}/{action}/{id}.html",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
    
                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
            }
    

    修改web.config配置

    添加完后并不能够映射路由,需要配置下web.config

     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
     </system.webServer>
    

    配置完后即可通过你自己配置的url访问您的网站了

  • 相关阅读:
    SharePoint Development
    win32- copyfile的使用
    SetWindowHookEx的复习
    C++ vector的使用
    关于char * 和 char [] 的一点理解
    CreateThread
    C++字符串大写字母转小写字母
    字符串逆序
    使用RegSetValueEx创建键值
    EnumColorProfiles WcsGetDefaultColorProfile WcsSetDefaultColorProfile的使用
  • 原文地址:https://www.cnblogs.com/liujiaxian/p/6336827.html
Copyright © 2011-2022 走看看