zoukankan      html  css  js  c++  java
  • Asp.net Web Api 路由匹配

    using System.Web.Mvc;
    using System.Web.Routing;
    
    namespace KingT.Web.TimeLine
    {
        public class RouteConfig
        {
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
                routes.MapRoute(
                    name: "TimeLine",
                    url: "tl/{visitId}/{from}/{to}",
                    defaults: new { controller = "Home", action = "Index", from = UrlParameter.Optional, to = UrlParameter.Optional }
                );
           //如果能匹配到这一个就不再向下匹配 
                routes.MapRoute(
                    name: "TimeLineSetting",
                    url: "setting",
                    defaults: new { controller = "Home", action = "Setting" }
                );
    
                routes.MapRoute(
                    name: "TimeLineSettingItem",
                    url: "setting/{item}",
                    defaults: new { controller = "Home", action = "SettingItem" }
                );
    
                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
            }
        }
    }

    http://localhost:8099/tl/2015122800143/2015-12-24/2016-1-28 可以匹配第一个、

    routes.MapRoute(
                    name: "TimeLine",
                    url: "{controller}/{action}/tl/{visitId}/{from}/{to}",
                    defaults: new { controller = "Home", action = "Index", from = UrlParameter.Optional, to = UrlParameter.Optional }
                );

    http://localhost:8099/Home/Index/tl/2015122800143/2015-12-24/2016-1-28 可以匹配上面的路由

  • 相关阅读:
    安装@vuecli "失败"
    随缘更新codeforces题解
    四边形不等式
    斯特林数与幂
    待补队列
    IOC容器Autofac的另类使用
    Qt4.x 手工编译及集成到VS2010
    发段代码,验证码,很久以前的,拿出来共享啦。
    WCF 第六章 序列化和编码 总结
    WCF 第六章 序列化与编码之XmlSerializer
  • 原文地址:https://www.cnblogs.com/jcbo/p/6903957.html
Copyright © 2011-2022 走看看