當前位置: 首頁>>代碼示例>>C#>>正文


C# Routing.Route類代碼示例

本文整理匯總了C#中System.Web.Routing.Route的典型用法代碼示例。如果您正苦於以下問題:C# Route類的具體用法?C# Route怎麽用?C# Route使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Route類屬於System.Web.Routing命名空間,在下文中一共展示了Route類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Match

		protected virtual bool Match (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
		{
			if (httpContext == null)
				throw new ArgumentNullException ("httpContext");
			if (route == null)
				throw new ArgumentNullException ("route");
			if (parameterName == null)
				throw new ArgumentNullException ("parameterName");
			if (values == null)
				throw new ArgumentNullException ("values");

			switch (routeDirection) {
			case RouteDirection.IncomingRequest:
				// LAMESPEC: .NET allows case-insensitive comparison, which violates RFC 2616
				return AllowedMethods.Contains (httpContext.Request.HttpMethod);

			case RouteDirection.UrlGeneration:
				// See: aspnetwebstack's WebAPI equivalent for details.
				object method;

				if (!values.TryGetValue (parameterName, out method))
					return true;

				// LAMESPEC: .NET allows case-insensitive comparison, which violates RFC 2616
				return AllowedMethods.Contains (Convert.ToString (method));

			default:
				throw new ArgumentException ("Invalid routeDirection: " + routeDirection);
			}
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:30,代碼來源:HttpMethodConstraint.cs

示例2: Match

 public bool Match(HttpContextBase httpContext, Route route, string parameterName, 
     RouteValueDictionary values, RouteDirection routeDirection)
 {
     Debug.WriteLine(httpContext.Request.HttpMethod == "GET");
     return httpContext.Request.UserAgent != null &&
         httpContext.Request.UserAgent.Contains(requiredUserAgent);
 }
開發者ID:NikolayKostadinov,項目名稱:ASP.Net-MVC5,代碼行數:7,代碼來源:UserAgentConstraint.cs

示例3: FactoryMethodWillCreateShellRoutes

        public void FactoryMethodWillCreateShellRoutes() {
            var settings = new ShellSettings { Name = "Alpha" };
            var builder = new ContainerBuilder();
            builder.RegisterType<ShellRoute>().InstancePerDependency();
            builder.RegisterAutoMocking();
            builder.Register(ctx => settings);

            var container = builder.Build();
            var buildShellRoute = container.Resolve<Func<RouteBase, ShellRoute>>();

            var routeA = new Route("foo", new MvcRouteHandler());
            var route1 = buildShellRoute(routeA);

            var routeB = new Route("bar", new MvcRouteHandler()) {
                DataTokens = new RouteValueDictionary { { "area", "Beta" } }
            };
            var route2 = buildShellRoute(routeB);

            Assert.That(route1, Is.Not.SameAs(route2));

            Assert.That(route1.ShellSettingsName, Is.EqualTo("Alpha"));
            Assert.That(route1.Area, Is.Null);

            Assert.That(route2.ShellSettingsName, Is.EqualTo("Alpha"));
            Assert.That(route2.Area, Is.EqualTo("Beta"));
        }
開發者ID:dioptre,項目名稱:nkd,代碼行數:26,代碼來源:ShellRouteTests.cs

示例4: Match

 /// <summary>
 /// 
 /// </summary>
 /// <param name="httpContext"></param>
 /// <param name="route"></param>
 /// <param name="parameterName"></param>
 /// <param name="values"></param>
 /// <param name="routeDirection"></param>
 /// <returns></returns>
 public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
 {
     if (values[parameterName].ToString().ToLower() == "rqitems")
         return true;
     else
         return false;
 }
開發者ID:jbunzel,項目名稱:MvcRQ_git,代碼行數:16,代碼來源:RouteConstraints.cs

示例5: Match

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
#endif
        {
            if (parameterName == null)
            {
                throw Error.ArgumentNull("parameterName");
            }

            if (values == null)
            {
                throw Error.ArgumentNull("values");
            }

            object value;
            if (values.TryGetValue(parameterName, out value) && value != null)
            {
                string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
                int length = valueString.Length;
                if (Length.HasValue)
                {
                    return length == Length.Value;
                }
                else
                {
                    return length >= MinLength.Value && length <= MaxLength.Value;
                }
            }
            return false;
        }
開發者ID:huangw-t,項目名稱:aspnetwebstack,代碼行數:29,代碼來源:LengthRouteConstraint.cs

示例6: MapRootArea

 public static void MapRootArea(this RouteCollection routes, string url, string rootNamespace, object defaults)
 {
     Route route = new Route(url, new MvcRouteHandler());
         route.DataTokens = new RouteValueDictionary(new { namespaces = new string[] { rootNamespace + ".Controllers" } });
         route.Defaults = new RouteValueDictionary(new { area = "root", action = "Index", controller = "Home", id = "" });
         routes.Add(route);
 }
開發者ID:cvasquez1425,項目名稱:ShareMockups,代碼行數:7,代碼來源:RouteHelper.cs

示例7: MapLocalizedRoute

        public static Route MapLocalizedRoute(this RouteCollection routes, string name, string url, object defaults,
            object constraints, string[] namespaces)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            var route = new Route(url, 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;
        
        }
開發者ID:saturn72,項目名稱:Saturn72.Web,代碼行數:29,代碼來源:RouteExtensions.cs

示例8: LocaleRoute

        public LocaleRoute(
                    string pattern, 
                    RouteValueDictionary defaults, 
                    RouteValueDictionary constraints,
                    RouteValueDictionary tokens,
                    string[] namespaces,
                    IRouteHandler routeHandler)
        {
            var localeConstraints = new RouteValueDictionary(constraints);
            localeConstraints.Add("locale", @"[a-zA-Z]{2}");

            _routeWithLocale = new Route(
                                    @"{locale}/" + pattern,
                                    defaults,
                                    localeConstraints,
                                    tokens,
                                    new LocaleRouteHandler(routeHandler));

            _routeWithoutLocale = new Route(
                                        pattern,
                                        defaults,
                                        constraints,
                                        tokens,
                                        new LocaleRouteHandler(routeHandler));

            if(namespaces != null && namespaces.Any()) {
                _routeWithLocale.DataTokens["Namespaces"] = namespaces;
                _routeWithoutLocale.DataTokens["Namespaces"] = namespaces;
            }
        }
開發者ID:jasonholloway,項目名稱:brigita,代碼行數:30,代碼來源:LocaleRoutes.cs

示例9: IsMatch

        protected override bool IsMatch(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {

            if (!base.IsMatch(httpContext, route, parameterName, values, routeDirection))
            {
                return false;
            }

            if (routeDirection == RouteDirection.UrlGeneration)
            {
                return true;
            }

            var encoded = values[parameterName].ToString();
            var decoded = SettingsHelper.SeoDecode(encoded, SeoUrlKeywordTypes.Category, 
                values.ContainsKey(Constants.Language) ? values[Constants.Language].ToString() : null);

            var childCategryId = decoded.Split(Separator.ToCharArray()).Last();

            var category = CartHelper.CatalogClient.GetCategoryById(childCategryId);

            if (category == null)
            {
                return false;
            }

            var outline = new BrowsingOutline(CartHelper.CatalogOutlineBuilder.BuildCategoryOutline(StoreHelper.CustomerSession.CatalogId, category));

            return ValidateCategoryPath(outline.ToString(), decoded);
        }
開發者ID:gitter-badger,項目名稱:vc-community-1.x,代碼行數:30,代碼來源:CategoryRouteConstraint.cs

示例10: CreateRouteEntry_IfDirectRouteProviderReturnsRouteWithEmptyActionDescriptors_Throws

        public void CreateRouteEntry_IfDirectRouteProviderReturnsRouteWithEmptyActionDescriptors_Throws()
        {
            // Arrange
            string areaPrefix = null;
            string controllerPrefix = null;
            Route route = new Route(url: null, routeHandler: null);
            route.DataTokens = new RouteValueDictionary();
            route.DataTokens.Add(RouteDataTokenKeys.Actions, new ActionDescriptor[0]);
            ActionDescriptor[] originalActions = route.GetTargetActionDescriptors();
            Assert.NotNull(originalActions); // Guard
            Assert.Equal(0, originalActions.Length); // Guard
            RouteEntry entry = new RouteEntry(name: null, route: route);
            IDirectRouteFactory factory = CreateStubRouteFactory(entry);
            ControllerDescriptor controllerDescriptor = CreateStubControllerDescriptor("IgnoreController");
            ActionDescriptor actionDescriptor = CreateStubActionDescriptor(controllerDescriptor, "IgnoreAction");
            IReadOnlyCollection<ActionDescriptor> actions = new ActionDescriptor[] { actionDescriptor };
            IInlineConstraintResolver constraintResolver =
                new Mock<IInlineConstraintResolver>(MockBehavior.Strict).Object;

            // Act & Assert
            string expectedMessage = "The route does not have any associated action descriptors. Routing requires " +
                "that each direct route map to a non-empty set of actions.";
            Assert.Throws<InvalidOperationException>(() => DefaultDirectRouteProvider.CreateRouteEntry(areaPrefix,
                controllerPrefix, factory, actions, constraintResolver, targetIsAction: false), expectedMessage);
        }
開發者ID:ahmetgoktas,項目名稱:aspnetwebstack,代碼行數:25,代碼來源:DefaultDirectRouteProviderTest.cs

示例11:

 bool IRouteConstraint.Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
 {
     if (!values.ContainsKey(parameterName))
         return false;
     var parameterValue = values[parameterName];
     return parameterValue != null && Enum.GetNames(EnumType).Contains(parameterValue.ToString(), StringComparer.OrdinalIgnoreCase);
 }
開發者ID:rupertbates,項目名稱:GuardianReviewsAzure,代碼行數:7,代碼來源:UrlEnumMatchConstraint.cs

示例12: Match

 protected override bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
 {
     var methodOverride = httpContext.Request.Unvalidated().Form["X-HTTP-Method-Override"];
     if (methodOverride == null) return base.Match(httpContext, route, parameterName, values, routeDirection);
     return AllowedMethods.Any(m => string.Equals(m, httpContext.Request.HttpMethod, StringComparison.OrdinalIgnoreCase))
         && AllowedMethods.Any(m => string.Equals(m, methodOverride, StringComparison.OrdinalIgnoreCase));
 }
開發者ID:saibalghosh,項目名稱:UCosmic,代碼行數:7,代碼來源:HttpMethodOverrideConstraint.cs

示例13: IsMatch

        protected override bool IsMatch(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            if (routeDirection == RouteDirection.UrlGeneration)
            {
                return true;
            }

            if (!base.IsMatch(httpContext, route, parameterName, values, routeDirection))
            {
                return false;
            }

            //First check that language matches regex pattern
            object parameterValue; 
            values.TryGetValue(parameterName, out parameterValue);
            var parameterValueString = Convert.ToString(parameterValue, CultureInfo.InvariantCulture);
            var constraintsRegEx = string.Format("^({0})$", Constants.LanguageRegex);
            if (!Regex.IsMatch(parameterValueString, constraintsRegEx, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Compiled))
            {
                return false;
            }

            try
            {
                var culture = CultureInfo.CreateSpecificCulture(parameterValueString);
                //If culture is created then it is correct
            }
            catch
            {
                //Language is not valid
                return false;
            }

            return true;
        }
開發者ID:gitter-badger,項目名稱:vc-community-1.x,代碼行數:35,代碼來源:LanguageRouteConstraint.cs

示例14: Match

 public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
 {
     if (RequireAnonymous)
         return !httpContext.Request.IsAuthenticated;
     else
         return httpContext.Request.IsAuthenticated;
 }
開發者ID:zaLTys,項目名稱:osfi,代碼行數:7,代碼來源:AuthenticatedConstraint.cs

示例15: RegisterRoutes

		internal static void RegisterRoutes()
		{
			var urls = new[] 
		    { 
		        "ssr-jquip.all", 
		        "ssr-includes.js", 
		        "ssr-includes.css", 
		        "ssr-includes.tmpl", 
		        "ssr-results"
		    };
			var routes = RouteTable.Routes;
			var handler = new MiniProfilerRouteHandler(new MiniProfilerHandler());
			var prefix = (Profiler.Settings.RouteBasePath ?? "").Replace("~/", "").WithTrailingSlash();

			using (routes.GetWriteLock())
			{
				foreach (var url in urls)
				{
					var route = new Route(prefix + url, handler) {
						// we have to specify these, so no MVC route helpers will match, e.g. @Html.ActionLink("Home", "Index", "Home")
						Defaults = new RouteValueDictionary(new { controller = "MiniProfilerHandler", action = "ProcessRequest" })
					};

					// put our routes at the beginning, like a boss
					routes.Insert(0, route);
				}
			}
		}
開發者ID:CLupica,項目名稱:ServiceStack,代碼行數:28,代碼來源:MiniProfiler.cs


注:本文中的System.Web.Routing.Route類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。