• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Routing.Route类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.Routing.Route的典型用法代码示例。如果您正苦于以下问题:C# Route类的具体用法?C# Route怎么用?C# Route使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Route类属于System.Web.Routing命名空间,在下文中一共展示了Route类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Match

            public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
            {
                if (routeDirection == RouteDirection.IncomingRequest)
                {
                    if (_alreadyProcessed.ContainsKey(httpContext.Request.Url.AbsolutePath))
                    {
                        return _alreadyProcessed[httpContext.Request.Url.AbsolutePath];
                    }
                    var pathParts = httpContext.Request.Url.AbsolutePath.Split('/').ToList();
                    var backOfficePart = pathParts.IndexOf(_appContext.Settings.RebelPaths.BackOfficePath);
                    //ensure there's enough parts to match
                    if (backOfficePart == -1 || ((pathParts.Count - 1) < backOfficePart + 2))
                    {
                        _alreadyProcessed.AddOrUpdate(httpContext.Request.Url.AbsolutePath, false, (k, v) => false);
                        return false;
                    }
                    //ensure were matching the correct area
                    if (pathParts[backOfficePart + 1] != _areaName)
                    {
                        _alreadyProcessed.AddOrUpdate(httpContext.Request.Url.AbsolutePath, false, (k, v) => false);
                        return false;
                    }
                    //+2 because the area name comes after the back office path
                    var controller = pathParts[backOfficePart + 2];
                    if (_toIgnore.InvariantContains(controller))
                    {
                        _alreadyProcessed.AddOrUpdate(httpContext.Request.Url.AbsolutePath, true, (k, v) => true);
                        return true;
                    }
                }

                return false;

            }
开发者ID:RebelCMS,项目名称:rebelcmsxu5,代码行数:34,代码来源:IgnorePluginRoute.cs


示例17: Match

 public bool Match(HttpContextBase httpContext, Route route, string parameterName, 
                   RouteValueDictionary values, RouteDirection routeDirection)
 {
     bool result = httpContext.Request.UserAgent != null &&
         httpContext.Request.UserAgent.Contains(requiredUserAgent);
     return result;
 }
开发者ID:akhuang,项目名称:Books-SourceCode,代码行数:7,代码来源:UserAgentConstraint.cs


示例18:

        bool IRouteConstraint.Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            var Controllers = CoreConfiguration.Instance.IgnorableControllers.Split(',');
            var Actions = CoreConfiguration.Instance.IgnorableActions.Split(',');

            return !Controllers.Any(Controller => Controller == values["controller"].ToString()) && !Actions.Any(Action => Action == values["action"].ToString());
        }
开发者ID:CoderNumber1,项目名称:Laziton,代码行数:7,代码来源:RouteIgnoreConstraint.cs


示例19: Match

 // To only allow *supported* cultures as the first part of the route, instead of  anything in the format xx or xx-xx comment the lower method
 // and uncomment this one, and make CultureManager.CultureIsSupported public.
 //public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
 //{
 //    if (!values.ContainsKey(parameterName))
 //        return false;
 //    string potentialCultureName = (string)values[parameterName];
 //    return CultureManager.CultureIsSupported(potentialCultureName);
 //}
 public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
 {
     if (!values.ContainsKey(parameterName))
         return false;
     string potentialCultureName = (string)values[parameterName];
     return CultureFormatChecker.FormattedAsCulture(potentialCultureName);
 }
开发者ID:babelfish42,项目名称:OnlineShop,代码行数:16,代码来源:CultureRouteConstraint.cs


示例20: Match

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            var blogRepo = DependencyResolver.Current.GetService<IRepository<Data.Blog>>();
            var httpContextService = DependencyResolver.Current.GetService<IHttpContextService>();

            return DependencyResolver.Current.GetService<IRepository<Redirect>>().GetRedirectFor(httpContext.Request.Url.LocalPath.TrimStart('/'), blogRepo.GetCurrentBlog(httpContextService).Id) != null;
        }
开发者ID:stilldesign,项目名称:StaticVoid.Blog,代码行数:7,代码来源:RedirectRouteConstraint.cs



注:本文中的System.Web.Routing.Route类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Routing.RouteBase类代码示例发布时间:2022-05-26
下一篇:
C# Routing.RequestContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap