/// <summary>
 /// 注册用于生成静态页的路由
 /// </summary>
 /// <param name="directoryParameterName">文件夹参数名称</param>
 /// <param name="cycleMode">配置此项(MM:每月更新;WW:每周更新;DD:每日更新)用于生成静态路由</param>
 public static void RegisterStaticizeRoutes(string directoryParameterName = "staticizeDirectory", string cycleMode = "DD")
 {
     string folderName = string.Empty;
     if (!string.IsNullOrWhiteSpace(directoryParameterName))
         folderName = DateTime.Now.GetDirectoryName(cycleMode);
     foreach (MvcRouteElement route in YuYuMvcStaticizeRouteCollectionConfigurationSection.Routes.RouteElements)
     {
         RouteValueDictionary defaults = Helper.CreateRouteValueDictionary(route.Defaults.CreateObject());
         RouteValueDictionary constraints = Helper.CreateRouteValueDictionary(route.Constraints.CreateObject());
         if (!string.IsNullOrWhiteSpace(directoryParameterName))
             defaults.Add(directoryParameterName, folderName);
         Route item = null;
         if (!string.IsNullOrWhiteSpace(route.Domain))
             item = new DomainRoute(route.Domain, route.Url, route.RouteHandler)
             {
                 Defaults = defaults,
                 Constraints = constraints,
                 DataTokens = new RouteValueDictionary(),
                 Port = route.Port,
                 Protocol = route.Protocol,
             };
         else
             item = new Route(route.Url, route.RouteHandler)
             {
                 Defaults = defaults,
                 Constraints = constraints,
                 DataTokens = new RouteValueDictionary()
             };
         if (!string.IsNullOrWhiteSpace(route.Namespaces))
             item.DataTokens["Namespaces"] = route.Namespaces.Split(',');
         StaticizeRoutes.Add(route.Name, item);
     }
 }
示例#2
0
        public override void RegisterArea(AreaRegistrationContext context)
        {
            RouteValueDictionary dataTokens = new RouteValueDictionary();

            dataTokens["Namespaces"]           = new string[] { "Pokefans.Areas.sfc.Controllers" };
            dataTokens["UseNamespaceFallback"] = false;

            var route = new DomainRoute(
                "sfc." + ConfigurationManager.AppSettings["Domain"],
                "{controller}/{action}/{id}",
                new { action = "Index", controller = "SfcHome", id = UrlParameter.Optional },
                dataTokens
                );

            context.Routes.Add("sfcarcrypt", new DomainRoute(
                                   "sfc." + ConfigurationManager.AppSettings["Domain"],
                                   "tools/arcrypt",
                                   new { action = "ArCrypt", controller = "SfcHome" }/*,
                                                                                      * dataTokens*/
                                   ));


            // Default Route
            context.Routes.Add("sfcdefault", route);
        }
        /// <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);
            }
        }
示例#4
0
        /// <summary>
        /// Gets the tenantId based on the domain.
        /// </summary>
        /// <param name="routeData"></param>
        /// <returns>The Tennant Id, which is the Account.Id associated with the domain in the route information.</returns>
        public static int GetTenantId(this System.Web.Routing.RouteData routeData)
        {
            DomainRoute       dr = (DomainRoute)routeData.Route;
            ShoelaceDbContext db = new ShoelaceDbContext();
            int     tenantId     = -1;
            var     sub          = routeData.Values["subdomain"] as string;
            Account acc          = null;

            if (sub != null)
            {
                acc = db.Accounts.FirstOrDefault(x => x.Subdomain == sub);
            }

            if (null != acc)
            {
                tenantId = acc.Id;
            }
            else
            {
                acc = db.Accounts.FirstOrDefault(x => x.VanityDomain == dr.Domain);
                if (acc != null)
                {
                    tenantId = acc.Id;
                }
            }
            return(tenantId);
        }
        public static Route MapRouteDomain(this RouteCollection routes, string name, string domain, string url, object defaults, object constraints, string[] namespaces)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            DomainRoute route = new DomainRoute(domain, url, defaults, new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(defaults),
                Constraints = new RouteValueDictionary(constraints),
                DataTokens = new RouteValueDictionary()
            };

            if ((namespaces != null) && (namespaces.Length > 0))
            {
                route.DataTokens["Namespaces"] = namespaces;
            }

            routes.Add(name, route);

            return route;
        }
        public override void RegisterArea(AreaRegistrationContext context)
        {
            var route = new DomainRoute(
                "{account}." + DoverApplication.DomainName,
                "CloudTalkModule/{action}/{id}",
                new { controller = "CloudTalkModule", action = "Index", id = UrlParameter.Optional }
                );

            route.Area = AreaName;

            context.Routes.Add("CloudTalkModuleRoute", route);

            //context.MapRoute(
            //    "CloudTalkModuleRoute",
            //    "CloudTalkModule/{action}/{id}",
            //    new { controller = "CloudTalkModule", action = "Index", id = UrlParameter.Optional }
            //);
        }
示例#7
0
        public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary <string, object> htmlAttributes, bool requireAbsoluteUrl)
        {
            if (requireAbsoluteUrl)
            {
                HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current);
                RouteData       routeData      = RouteTable.Routes.GetRouteData(currentContext);

                routeData.Values["controller"] = controllerName;
                routeData.Values["action"]     = actionName;

                DomainRoute domainRoute = routeData.Route as DomainRoute;
                if (domainRoute != null)
                {
                    DomainData domainData = domainRoute.GetDomainData(new RequestContext(currentContext, routeData), routeData.Values);
                    return(htmlHelper.ActionLink(linkText, actionName, controllerName, domainData.Protocol, domainData.HostName, domainData.Fragment, routeData.Values, null));
                }
            }
            return(htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes));
        }
示例#8
0
        public static string Action(this UrlHelper urlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, bool requireAbsoluteUrl)
        {
            if (requireAbsoluteUrl)
            {
                HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current);
                RouteData       routeData      = RouteTable.Routes.GetRouteData(currentContext);

                routeData.Values["controller"] = controllerName;
                routeData.Values["action"]     = actionName;

                DomainRoute domainRoute = routeData.Route as DomainRoute;
                if (domainRoute != null)
                {
                    DomainData domainData = domainRoute.GetDomainData(new RequestContext(currentContext, routeData), routeData.Values);
                    return(urlHelper.Action(actionName, controllerName, routeData.Values, domainData.Protocol, domainData.HostName));
                }
            }
            return(urlHelper.Action(actionName, controllerName, routeValues));
        }
 /// <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;
 }
 /// <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;
 }
示例#11
0
 /// <summary>
 /// 创建二级域名路由
 /// </summary>
 /// <param name="page"></param>
 /// <returns></returns>
 private DomainRoute CreateDomainRoute(EPages page)
 {
     var pageHandler = Cdev.Infrastructure.CdevContainer.Ins.Resolve<BasePagesHandler>(page.PagesHandler);
     var route = new DomainRoute(
       this.GetDomain(page),
       this.GetPageUrl(page),
       new RouteValueDictionary(pageHandler.GetRouteData(page))
     );
     return route;
 }
示例#12
0
        public static string GetDomain(this RouteData routeData)
        {
            DomainRoute dr = (DomainRoute)routeData.Route;

            return(dr.Domain);
        }