Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="urlHelper"></param>
 /// <param name="actionName"></param>
 /// <param name="controllerName"></param>
 /// <param name="routeValues"></param>
 /// <param name="requireAbsoluteUrl"></param>
 /// <returns></returns>
 public static string Action(this UrlHelper urlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, bool requireAbsoluteUrl)
 {
     if (requireAbsoluteUrl)
     {
         RouteBase   route       = RouteTable.Routes.GetVirtualPath(_GetRequestContext(urlHelper, controllerName, actionName), routeValues).Route;
         DomainRoute domainRoute = route as DomainRoute;
         if (domainRoute != null)
         {
             DomainData domain    = domainRoute.GetDomainData(urlHelper.RequestContext, routeValues);
             string     urlString = urlHelper.Action(actionName, controllerName, routeValues, domain.Protocol, domain.Host);
             return(Regex.Replace(urlString, @"\:\d+", domain.Port > 0 ? ":" + domain.Port : string.Empty));
         }
     }
     return(urlHelper.Action(actionName, controllerName, routeValues));
 }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="htmlHelper"></param>
 /// <param name="linkText"></param>
 /// <param name="actionName"></param>
 /// <param name="controllerName"></param>
 /// <param name="routeValues"></param>
 /// <param name="htmlAttributes"></param>
 /// <param name="requireAbsoluteUrl"></param>
 /// <returns></returns>
 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 domain = domainRoute.GetDomainData(new RequestContext(currentContext, routeData), routeData.Values);
             return(htmlHelper.ActionLink(linkText, actionName, controllerName, domain.Protocol, domain.Host, string.Empty, routeData.Values, null));
         }
     }
     return(htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes));
 }
Beispiel #5
0
        /// <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);
            }
        }
Beispiel #6
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);
            }
        }