コード例 #1
0
ファイル: UrlHelperEx.cs プロジェクト: smorey2/bclcontrib-web
        public static string GenerateUrl(out IDynamicNode node, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues)
        {
            var dynamicUrl = GenerateUrl(out node, routeName, actionName, controllerName, routeValues, routeCollection, requestContext, includeImplicitMvcValues);

            if (dynamicUrl == null)
            {
                return(dynamicUrl);
            }
            if (!string.IsNullOrEmpty(fragment))
            {
                dynamicUrl = dynamicUrl + "#" + fragment;
            }
            if (string.IsNullOrEmpty(protocol) && string.IsNullOrEmpty(hostName))
            {
                return(dynamicUrl);
            }
            var url = requestContext.HttpContext.Request.Url;

            protocol = (!string.IsNullOrEmpty(protocol) ? protocol : Uri.UriSchemeHttp);
            hostName = (!string.IsNullOrEmpty(hostName) ? hostName : url.Host);
            var port   = string.Empty;
            var scheme = url.Scheme;

            if (string.Equals(protocol, scheme, StringComparison.OrdinalIgnoreCase))
            {
                port = (url.IsDefaultPort ? string.Empty : (":" + Convert.ToString(url.Port, CultureInfo.InvariantCulture)));
            }
            return(protocol + Uri.SchemeDelimiter + hostName + port + dynamicUrl);
        }
コード例 #2
0
        private static string GetControllerNameFromNode(IDynamicNode node)
        {
            // func
            var func = node.Get <Func <IDynamicNode, RouteData> >();

            if (func != null)
            {
                throw new InvalidOperationException("Controller name: Func not allowed");
            }
            // single | many
            var route = node.Get <Route>();

            if (route == null)
            {
                var multiRoutes = node.GetMany <Route>();
                if (multiRoutes != null)
                {
                    route = multiRoutes.FirstOrDefault();
                }
            }
            if (route != null)
            {
                return((string)route.Defaults["controller"]);
            }
            throw new InvalidOperationException("No controller set for node");
        }
コード例 #3
0
        public static void SetRouteDefaults(IEnumerable <Route> routes, IDynamicNode node)
        {
            var id = node.Key;

            foreach (var route in routes)
            {
                route.DataTokens["dynamicID"]   = id;
                route.DataTokens["dynamicNode"] = node;
                route.Defaults["dynamicID"]     = id;
            }
        }
コード例 #4
0
ファイル: UrlHelperEx.cs プロジェクト: smorey2/bclcontrib-web
        public static string GenerateUrl(out IDynamicNode node, string routeName, string actionName, string controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues)
        {
            if (routeCollection == null)
            {
                throw new ArgumentNullException("routeCollection");
            }
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }
            var values = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, requestContext.RouteData.Values, routeValues, includeImplicitMvcValues);
            var data   = routeCollection.GetVirtualPathForArea(requestContext, routeName, values);

            if (data == null)
            {
                node = null;
                return(null);
            }
            node = (IDynamicNode)data.DataTokens["dynamicNode"];
            return(PathHelpers.GenerateClientUrl(requestContext.HttpContext, data.VirtualPath));
        }