Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="routes"></param>
        /// <param name="name"></param>
        /// <param name="protocol"></param>
        /// <param name="domain"></param>
        /// <param name="port"></param>
        /// <param name="url"></param>
        /// <param name="defaults"></param>
        /// <param name="constraints"></param>
        /// <param name="namespaces"></param>
        /// <returns></returns>
        public static Route MapDomainRoute(this System.Web.Routing.RouteCollection routes, string name, string protocol, string domain, int port, string url, object defaults, object constraints, string[] namespaces)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (domain == null)
            {
                throw new ArgumentNullException("domain");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            Route route = new DomainRoute(domain, url, new MvcRouteHandler())
            {
                Defaults    = RouteValueDictionaryHelper.CreateRouteValueDictionary(defaults),
                Constraints = RouteValueDictionaryHelper.CreateRouteValueDictionary(constraints),
                DataTokens  = new RouteValueDictionary(),
                Protocol    = protocol,
                Port        = port,
            };

            if (namespaces.IsNotNullOrEmpty())
            {
                route.DataTokens["Namespaces"] = namespaces;
            }
            routes.Add(name, route);
            return(route);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="routes"></param>
        /// <param name="name"></param>
        /// <param name="protocol"></param>
        /// <param name="domain"></param>
        /// <param name="port"></param>
        /// <param name="url"></param>
        /// <param name="physicalFile"></param>
        /// <param name="checkPhysicalUrlAccess"></param>
        /// <param name="defaults"></param>
        /// <param name="constraints"></param>
        /// <param name="dataTokens"></param>
        /// <returns></returns>
        public static Route MapDomainPageRoute(this System.Web.Routing.RouteCollection routes, string name, string protocol, string domain, int port, string url, string physicalFile, bool checkPhysicalUrlAccess, object defaults, object constraints, object dataTokens)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (domain == null)
            {
                throw new ArgumentNullException("domain");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            Route route = new DomainRoute(domain, url, new PageRouteHandler(physicalFile, checkPhysicalUrlAccess))
            {
                Defaults    = RouteValueDictionaryHelper.CreateRouteValueDictionary(defaults),
                Constraints = RouteValueDictionaryHelper.CreateRouteValueDictionary(constraints),
                DataTokens  = RouteValueDictionaryHelper.CreateRouteValueDictionary(dataTokens),
                Protocol    = protocol,
                Port        = port,
            };

            routes.Add(name, route);
            return(route);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 注册路由
 /// </summary>
 /// <param name="routes">RouteCollection</param>
 public static void RegisterPageRoutes(System.Web.Routing.RouteCollection routes)
 {
     foreach (FileRouteElement route in YuYuWebConfigurationSectionGroup.YuYuFileRouteCollectionConfigurationSection.Routes.RouteElements)
     {
         RouteValueDictionary defaults    = RouteValueDictionaryHelper.CreateRouteValueDictionary(route.Defaults.CreateObject());
         RouteValueDictionary constraints = RouteValueDictionaryHelper.CreateRouteValueDictionary(route.Constraints.CreateObject());
         if (string.IsNullOrWhiteSpace(route.Domain))
         {
             routes.Add(route.Name, new Route(route.Url, defaults, constraints, route.RouteHandler ?? YuYuWebConfigurationSectionGroup.YuYuFileRouteCollectionConfigurationSection.CreateDefaultRouteHandler(route.PhysicalFile, route.CheckPhysicalUrlAccess)));
         }
         else
         {
             routes.Add(route.Name, new DomainRoute(route.Domain, route.Url, route.RouteHandler ?? YuYuWebConfigurationSectionGroup.YuYuFileRouteCollectionConfigurationSection.CreateDefaultRouteHandler(route.PhysicalFile, route.CheckPhysicalUrlAccess))
             {
                 Defaults    = defaults,
                 Constraints = constraints,
                 DataTokens  = new RouteValueDictionary(),
                 Port        = route.Port,
                 Protocol    = route.Protocol,
             });
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 注册路由
        /// </summary>
        /// <param name="routes">RouteCollection</param>
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            foreach (MvcRouteElement route in YuYuMvcConfigurationSectionGroup.RoutesSection.Routes.RouteElements)
            {
                RouteValueDictionary defaults    = RouteValueDictionaryHelper.CreateRouteValueDictionary(route.Defaults.CreateObject());
                RouteValueDictionary constraints = RouteValueDictionaryHelper.CreateRouteValueDictionary(route.Constraints.CreateObject());
                Route item = null;
                if (route.Domain.IsNullOrWhiteSpace())
                {
                    item = new Route(route.Url, route.RouteHandler)
                    {
                        Defaults    = defaults,
                        Constraints = constraints,
                        DataTokens  = new RouteValueDictionary()
                    }
                }
                ;
                else
                {
                    item = new DomainRoute(route.Domain, route.Url, route.RouteHandler)
                    {
                        Defaults    = defaults,
                        Constraints = constraints,
                        DataTokens  = new RouteValueDictionary(),
                        Port        = route.Port,
                        Protocol    = route.Protocol,
                    }
                };
                if (route.Namespaces.IsNotNullOrWhiteSpace())
                {
                    item.DataTokens["Namespaces"] = route.Namespaces.Split(',');
                }
                routes.Add(route.Name, item);
            }
        }