zoukankan      html  css  js  c++  java
  • mvc3的Url地址重写与优化

    Url地址重写与优化的作用主要表现如下

    ⒈缩短Url,隐藏实际路径提高安全性。
    ⒉易于用户记忆和键入。
    ⒊易于被搜索引擎收录。
    以下是我在MVC3中准备重写的一些常见的Url
    http://www.xxxx.com/pub/users   //用户广场
    http://www.xxxx.com/zhangsan    //用户空间
    http://www.xxxx.com/zhangsan/photos  //用户所有照片
    http://www.xxxx.com/zhangsan/photos?pid=12334324  //用户指定照片
    http://www.xxxx.com/zhangsan/photos/date-2012-12  //用户指定时间拍摄的照片
    http://www.xxxx.com/zhangsan/photos/date-2012-12?pid=122343243  //用户指定时间拍摄的照片  从指定照片开始
    http://www.xxxx.com/zhangsan/photos/tag-美女  //用户拍摄的标签为美女的照片
     
    我只要在Global.asax.cs文件中做如下配置即可达到重写目的
     public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
                routes.MapRoute(
                   "Pub-User",
                   "pub/{action}",
                   new { controller = "Pub", action = "Index" }
                   );
    
                routes.MapRoute(
                   "User-Space",
                   "{userid}",
                   new { controller = "User", action = "Index"}
                   );
    
                routes.MapRoute(
                  "User-Photos",
                  "{userid}/Photos",
                  new { controller = "Space", action = "PhotoViews" ,pid = "[0-9]{6,}"}
                  );
    
                routes.MapRoute(
                  "User-Photos-date",
                  "{userid}/Photos/date-{year}-{month}",
                  new { controller = "Space", action = "PhotoViewMonths", year = "[0-9]{4}", month = "[0-9]{1,2}" }
                  );
    
                routes.MapRoute(
                  "User-Photos-tag",
                  "{userid}/Photos/tag-{tag}",
                  new { controller = "Space", action = "PhotoViewTags" }
                  );
    
                routes.MapRoute(
                    "Default", // Route name
                    "", // URL with parameters
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                );
            }
    
  • 相关阅读:
    一些坑点
    [Luogu P4168] [Violet]蒲公英 (分块)
    冬令营颓废笔记
    WC2019 填坑记
    [Luogu P1829] [国家集训队]Crash的数字表格 / JZPTAB (莫比乌斯反演)
    [Luogu P2522] [HAOI2011]Problem b (莫比乌斯反演)
    [Luogu P3327] [SDOI2015]约数个数和 (莫比乌斯反演)
    [Luogu P3455] [POI2007]ZAP-Queries (莫比乌斯反演 )
    [Luogu P2257] YY的GCD (莫比乌斯函数)
    杭电 1166 敌兵布阵 (线段树)
  • 原文地址:https://www.cnblogs.com/huangzelin/p/3015749.html
Copyright © 2011-2022 走看看