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访问您的网站了

  • 相关阅读:
    Python并发(一)
    Python协程详解(二)
    Python协程详解(一)
    Python装饰器
    ●BZOJ 3676 [Apio2014]回文串
    ●POJ 3974 Palindrome(Manacher)
    ●BZOJ 1692 [Usaco2007 Dec]队列变换
    ●BZOJ 4698 Sdoi2008 Sandy的卡片
    ●BZOJ 4516 [Sdoi2016]生成魔咒
    ●BZOJ 3238 [Ahoi2013]差异
  • 原文地址:https://www.cnblogs.com/liujiaxian/p/6336827.html
Copyright © 2011-2022 走看看