Ejemplo n.º 1
0
    /// <summary>
    /// 获取指定区域的简单区域路由表实例,如果没有则创建一个。
    /// </summary>
    /// <param name="context">区域注册上下文</param>
    /// <returns>内建的简单区域路由表实例</returns>
    public static SimpleAreaRouteTable SimpleRouteTable( this AreaRegistrationContext context )
    {
      if ( context == null )
        throw new ArgumentNullException( "context" );


      var routes = context.Routes;
      var areaName = context.AreaName;
      var namespaces = context.Namespaces.IfNull( new string[0], n => n.ToArray() );
      var useNamespaceFallback = namespaces.Length == 0;

      lock ( routes )
      {
        var routeTable = routes.OfType<SimpleAreaRouteTable>().FirstOrDefault( route => route.AreaName.EqualsIgnoreCase( areaName ) );
        if ( routeTable == null )
          routes.Add( routeTable = new SimpleAreaRouteTable( areaName, namespaces, useNamespaceFallback ) );
        return routeTable;
      }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// 映射 MVC 默认路由规则
        /// </summary>
        /// <param name="routeTable">简单路由表实例</param>
        /// <param name="defaultController">默认的 Controller</param>
        /// <param name="defaultAction">默认的 Action</param>
        /// <returns>返回简单路由表实例,便于链式注册</returns>
        public static SimpleAreaRouteTable MapDefaultRoute(this SimpleAreaRouteTable routeTable, string defaultController = null, string defaultAction = null)
        {
            if (defaultController == null && defaultAction != null)
            {
                throw new ArgumentNullException("defaultController");
            }

            routeTable.MapRoute("~/{controller}/{action}");

            if (defaultController != null)
            {
                routeTable.MapRoute("~/{action}", new { controller = defaultController });
            }

            if (defaultAction != null)
            {
                routeTable.MapRoute("~/", new { controller = defaultController, action = defaultAction });
            }

            return(routeTable);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取指定区域的简单区域路由表实例,如果没有则创建一个。
        /// </summary>
        /// <param name="context">区域注册上下文</param>
        /// <returns>内建的简单区域路由表实例</returns>
        public static SimpleAreaRouteTable SimpleRouteTable(this AreaRegistrationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }


            var routes               = context.Routes;
            var areaName             = context.AreaName;
            var namespaces           = context.Namespaces.IfNull(new string[0], n => n.ToArray());
            var useNamespaceFallback = namespaces.Length == 0;

            lock ( routes )
            {
                var routeTable = routes.OfType <SimpleAreaRouteTable>().FirstOrDefault(route => route.AreaName.EqualsIgnoreCase(areaName));
                if (routeTable == null)
                {
                    routes.Add(routeTable = new SimpleAreaRouteTable(areaName, namespaces, useNamespaceFallback));
                }
                return(routeTable);
            }
        }