Example #1
0
 /// <summary>
 /// 映射一个 Action 路由
 /// </summary>
 /// <param name="routeTable">简单路由表实例</param>
 /// <param name="urlPattern">URL 模式</param>
 /// <param name="controller">Controller 名称</param>
 /// <param name="action">Action 名称</param>
 /// <param name="queryKeys">可用于 QueryString 的路由值</param>
 /// <returns>返回简单路由表实例,便于链式注册</returns>
 public static SimpleRouteTable MapAction(this SimpleRouteTable routeTable, string urlPattern, string controller, string action, string[] queryKeys = null)
 {
     return(routeTable.MapRoute(urlPattern, urlPattern, new Dictionary <string, string>()
     {
         { "action", action }, { "controller", controller }
     }, queryKeys));
 }
Example #2
0
        /// <summary>
        /// 映射一个路由规则
        /// </summary>
        /// <param name="routeTable">简单路由表实例</param>
        /// <param name="name">路由规则名称</param>
        /// <param name="urlPattern">URL 模式</param>
        /// <param name="routeValues">默认/静态路由值</param>
        /// <param name="queryKeys">可用于 QueryString 的路由值</param>
        /// <returns>返回简单路由表实例,便于链式注册</returns>
        public static SimpleRouteTable MapRoute(this SimpleRouteTable routeTable, string name, string urlPattern, IDictionary <string, string> routeValues, string[] queryKeys = null)
        {
            if (routeTable == null)
            {
                throw new ArgumentNullException("routeTable");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (urlPattern == null)
            {
                throw new ArgumentNullException("urlPattern");
            }

            if (routeValues == null)
            {
                routeValues = new Dictionary <string, string>();
            }


            routeTable.AddRule(name, urlPattern, routeValues, queryKeys);
            return(routeTable);
        }
Example #3
0
    /// <summary>
    /// 获取内建的简单路由表实例,如果没有则创建一个。
    /// </summary>
    /// <param name="routes">系统路由集合</param>
    /// <returns>内建的简单路由表实例</returns>
    public static SimpleRouteTable SimpleRouteTable( this RouteCollection routes )
    {
      if ( routes == null )
        throw new ArgumentNullException( "routes" );

      lock ( routes )
      {
        var routeTable = routes.OfType<SimpleRouteTable>().FirstOrDefault( route => route.Name == "Mvc_BuiltIn" );
        if ( routeTable == null )
          routes.Add( routeTable = new SimpleRouteTable( "Mvc_BuiltIn", new MvcRouteHandler(), true ) );
        return routeTable;
      }
    }
Example #4
0
        /// <summary>
        /// 获取内建的简单路由表实例,如果没有则创建一个。
        /// </summary>
        /// <param name="routes">系统路由集合</param>
        /// <returns>内建的简单路由表实例</returns>
        public static SimpleRouteTable SimpleRouteTable(this RouteCollection routes)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }

            lock ( routes )
            {
                var routeTable = routes.OfType <SimpleRouteTable>().FirstOrDefault(route => route.Name == "Mvc_BuiltIn");
                if (routeTable == null)
                {
                    routes.Add(routeTable = new SimpleRouteTable("Mvc_BuiltIn", new MvcRouteHandler(), true));
                }
                return(routeTable);
            }
        }
Example #5
0
 /// <summary>
 /// 映射 MVC 默认路由规则
 /// </summary>
 /// <param name="routeTable">简单路由表实例</param>
 /// <returns>返回简单路由表实例,便于链式注册</returns>
 public static SimpleRouteTable MapDefaultRoute(this SimpleRouteTable routeTable)
 {
     return(routeTable.MapRoute("~/{controller}/{action}"));
 }
Example #6
0
 /// <summary>
 /// 映射一个路由规则
 /// </summary>
 /// <param name="routeTable">简单路由表实例</param>
 /// <param name="name">路由规则名称</param>
 /// <param name="urlPattern">URL 模式</param>
 /// <param name="routeValues">默认/静态路由值</param>
 /// <param name="queryKeys">可用于 QueryString 的路由值</param>
 /// <returns>返回简单路由表实例,便于链式注册</returns>
 public static SimpleRouteTable MapRoute(this SimpleRouteTable routeTable, string name, string urlPattern, object routeValues = null, string[] queryKeys = null)
 {
     return(MapRoute(routeTable, name, urlPattern, routeValues.ToPropertiesMap(), queryKeys));
 }
Example #7
0
 /// <summary>
 /// 映射一个路由规则
 /// </summary>
 /// <param name="routeTable">简单路由表实例</param>
 /// <param name="urlPattern">URL 模式</param>
 /// <param name="routeValues">默认/静态路由值</param>
 /// <param name="queryKeys">可用于 QueryString 的路由值</param>
 /// <returns>返回简单路由表实例,便于链式注册</returns>
 public static SimpleRouteTable MapRoute(this SimpleRouteTable routeTable, string urlPattern, IDictionary <string, string> routeValues, string[] queryKeys = null)
 {
     return(MapRoute(routeTable, urlPattern, urlPattern, routeValues, queryKeys));
 }