当前位置: 首页>>代码示例>>C#>>正文


C# Routing.RouteData类代码示例

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


RouteData类属于Microsoft.AspNet.Routing命名空间,在下文中一共展示了RouteData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RouteAsync

        public async Task RouteAsync(RouteContext context) {
            EnsureLoggers(context.HttpContext);
            using(_logger.BeginScope("SubdomainTemplateRoute.RouteAsync")) {
                var host = context.HttpContext.Request.Host.Value;

                if(host.Contains(":")) {
                    host = host.Substring(0, host.IndexOf(":"));
                }

                var values = _matcher.Match(host);
                if(values == null) {
                    _logger.Log(x => x.Verbose, x => x.LogVerbose(nameof(SubdomainTemplateRoute) + " " + Name + " - Host \"" + context.HttpContext.Request.Host + "\" did not match."));
                    return;
                }

                var oldRouteData = context.RouteData;
                var newRouteData = new RouteData(oldRouteData);

                newRouteData.DataTokens.MergeValues(DataTokens);
                newRouteData.Routers.Add(_target);
                newRouteData.Values.MergeValues(values);

                try {
                    context.RouteData = newRouteData;
                    await _innerRoute.RouteAsync(context);
                }
                finally {
                    if(!context.IsHandled) {
                        context.RouteData = oldRouteData;
                    }
                }
            }
        }
开发者ID:migrap,项目名称:Migrap.AspNet.Routing,代码行数:33,代码来源:SubdomainTemplateRoute.cs

示例2: ActionContext

        /// <summary>
        /// Creates a new <see cref="ActionContext"/>.
        /// </summary>
        /// <param name="httpContext">The <see cref="Http.HttpContext"/> for the current request.</param>
        /// <param name="routeData">The <see cref="AspNet.Routing.RouteData"/> for the current request.</param>
        /// <param name="actionDescriptor">The <see cref="Abstractions.ActionDescriptor"/> for the selected action.</param>
        /// <param name="modelState">The <see cref="ModelStateDictionary"/>.</param>
        public ActionContext(
            HttpContext httpContext,
            RouteData routeData,
            ActionDescriptor actionDescriptor,
            ModelStateDictionary modelState)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            if (routeData == null)
            {
                throw new ArgumentNullException(nameof(routeData));
            }

            if (actionDescriptor == null)
            {
                throw new ArgumentNullException(nameof(actionDescriptor));
            }

            if (modelState == null)
            {
                throw new ArgumentNullException(nameof(modelState));
            }

            HttpContext = httpContext;
            RouteData = routeData;
            ActionDescriptor = actionDescriptor;
            ModelState = modelState;
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:38,代码来源:ActionContext.cs

示例3: RouteAsync

        public async virtual Task RouteAsync(RouteContext context)
        {
            for (var i = 0; i < Count; i++)
            {
                var route = this[i];

                var oldRouteData = context.RouteData;

                var newRouteData = new RouteData(oldRouteData);
                newRouteData.Routers.Add(route);

                try
                {
                    context.RouteData = newRouteData;

                    await route.RouteAsync(context);
                    if (context.IsHandled)
                    {
                        break;
                    }
                }
                finally
                {
                    if (!context.IsHandled)
                    {
                        context.RouteData = oldRouteData;
                    }
                }
            }
        }
开发者ID:TerabyteX,项目名称:Routing,代码行数:30,代码来源:RouteCollection.cs

示例4: ExecuteResultAsync_InvokesForbiddenAsyncOnAllConfiguredSchemes

        public async Task ExecuteResultAsync_InvokesForbiddenAsyncOnAllConfiguredSchemes()
        {
            // Arrange
            var authProperties = new AuthenticationProperties();
            var authenticationManager = new Mock<AuthenticationManager>();
            authenticationManager
                .Setup(c => c.ForbidAsync("Scheme1", authProperties))
                .Returns(TaskCache.CompletedTask)
                .Verifiable();
            authenticationManager
                .Setup(c => c.ForbidAsync("Scheme2", authProperties))
                .Returns(TaskCache.CompletedTask)
                .Verifiable();
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(c => c.RequestServices).Returns(CreateServices());
            httpContext.Setup(c => c.Authentication).Returns(authenticationManager.Object);
            var result = new ForbidResult(new[] { "Scheme1", "Scheme2" }, authProperties);
            var routeData = new RouteData();

            var actionContext = new ActionContext(
                httpContext.Object,
                routeData,
                new ActionDescriptor());

            // Act
            await result.ExecuteResultAsync(actionContext);

            // Assert
            authenticationManager.Verify();
        }
开发者ID:phinq19,项目名称:git_example,代码行数:30,代码来源:ForbidResultTest.cs

示例5: RouteAsync

        public async Task RouteAsync(RouteContext context)
        {
            // Saving and restoring the original route data ensures that any values we
            // add won't 'leak' if action selection doesn't match.
            var oldRouteData = context.RouteData;

            // For diagnostics and link-generation purposes, routing should include
            // a list of IRoute instances that lead to the ultimate destination.
            // It's the responsibility of each IRouter to add the 'next' before 
            // calling it.
            var newRouteData = new RouteData(oldRouteData);
            newRouteData.Routers.Add(_next);

            var locale = GetLocale(context.HttpContext) ?? "en-US";
            newRouteData.Values.Add("locale", locale);

            try
            {
                context.RouteData = newRouteData;
                await _next.RouteAsync(context);
            }
            finally
            {
                if (!context.IsHandled)
                {
                    context.RouteData = oldRouteData;
                }
            }
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:29,代码来源:LocalizedRoute.cs

示例6: UpdateOnMissingTemplateAsync

 /// <summary>
 /// Updates the request when there is no template to render the content.
 /// </summary>
 internal async Task UpdateOnMissingTemplateAsync(RouteData routeData)
 {
     var __readonly = _readonly;
     _readonly = false;
     await _engine.UpdateRequestOnMissingTemplateAsync(routeData);
     _readonly = __readonly;
 }
开发者ID:ryanmcdonough,项目名称:Umbraco9,代码行数:10,代码来源:PublishedContentRequest.cs

示例7: ControllerRunner

 public ControllerRunner(string controller, string action, HttpContext httpContext, RouteData routeData)
 {
     _controller = controller;
     _action = action;
     _httpContext = httpContext;
     _routeData = routeData;
 }
开发者ID:jballe,项目名称:Lightcore,代码行数:7,代码来源:ControllerRunner.cs

示例8: RenderPlaceholderArgs

 public RenderPlaceholderArgs(HttpContext httpContext, RouteData routeData, Item item, string name, TextWriter output)
 {
     HttpContext = httpContext;
     RouteData = routeData;
     Item = item;
     Name = name;
     Output = output;
 }
开发者ID:jballe,项目名称:Lightcore,代码行数:8,代码来源:RenderPlaceholderArgs.cs

示例9: RenderRenderingArgs

 public RenderRenderingArgs(HttpContext httpContext, RouteData routeData, Item item, Rendering rendering, TextWriter output)
 {
     HttpContext = httpContext;
     RouteData = routeData;
     Item = item;
     Rendering = rendering;
     Output = output;
 }
开发者ID:jballe,项目名称:Lightcore,代码行数:8,代码来源:RenderRenderingArgs.cs

示例10: GetActionContext

        private static ActionContext GetActionContext(HttpContext httpContext)
        {
            var routeData = new RouteData();
            routeData.Routers.Add(Mock.Of<IRouter>());

            return new ActionContext(httpContext,
                                    routeData,
                                    new ActionDescriptor());
        }
开发者ID:ryanbrandenburg,项目名称:Mvc,代码行数:9,代码来源:CreatedAtRouteResultTests.cs

示例11: GetRoutes

		/// <summary>
		/// Gets the route information
		/// </summary>
		/// <param name="routeData">Raw route data from ASP.NET MVC</param>
		/// <returns>Processed route information</returns>
		public IEnumerable<RouteInfo> GetRoutes(RouteData routeData)
		{
			return _actionDescriptorsCollectionProvider.ActionDescriptors.Items
				.OfType<ControllerActionDescriptor>()
				.Where(a => a.AttributeRouteInfo?.Template != null)
				.Select(ProcessAttributeRoute)
				// Sort by Order then Precedence, same as InnerAttributeRoute
				.OrderBy(x => x.Order)
				.ThenBy(x => x.Precedence)
				.ThenBy(x => x.Url, StringComparer.Ordinal);
		}
开发者ID:modulexcite,项目名称:RouteJs,代码行数:16,代码来源:AttributeRouteFetcher.cs

示例12: OnBeforeAction

        public void OnBeforeAction(ActionDescriptor actionDescriptor, HttpContext httpContext, RouteData routeData)
        {
            string name = this.GetNameFromRouteContext(routeData);
            var telemetry = httpContext.RequestServices.GetService<RequestTelemetry>();

            if (!string.IsNullOrEmpty(name) && telemetry != null && telemetry is RequestTelemetry)
            {
                name = httpContext.Request.Method + " " + name;
                ((RequestTelemetry)telemetry).Name = name;
            }
        }
开发者ID:jango2015,项目名称:ApplicationInsights-aspnet5,代码行数:11,代码来源:OperationNameTelemetryInitializer.cs

示例13: RouteAsync

        public async Task RouteAsync([NotNull] RouteContext context)
        {
            var services = context.HttpContext.RequestServices;

            // Verify if AddMvc was done before calling UseMvc
            // We use the MvcMarkerService to make sure if all the services were added.
            MvcServicesHelper.ThrowIfMvcNotRegistered(services);

            EnsureLogger(context.HttpContext);
            using (_logger.BeginScope("MvcRouteHandler.RouteAsync"))
            {
                var actionSelector = services.GetRequiredService<IActionSelector>();
                var actionDescriptor = await actionSelector.SelectAsync(context);

                if (actionDescriptor == null)
                {
                    LogActionSelection(actionSelected: false, actionInvoked: false, handled: context.IsHandled);
                    return;
                }

                // Replacing the route data allows any code running here to dirty the route values or data-tokens
                // without affecting something upstream.
                var oldRouteData = context.RouteData;
                var newRouteData = new RouteData(oldRouteData);

                if (actionDescriptor.RouteValueDefaults != null)
                {
                    foreach (var kvp in actionDescriptor.RouteValueDefaults)
                    {
                        if (!newRouteData.Values.ContainsKey(kvp.Key))
                        {
                            newRouteData.Values.Add(kvp.Key, kvp.Value);
                        }
                    }
                }

                try
                {
                    context.RouteData = newRouteData;

                    await InvokeActionAsync(context, actionDescriptor);
                    context.IsHandled = true;
                }
                finally
                {
                    if (!context.IsHandled)
                    {
                        context.RouteData = oldRouteData;
                    }
                }

                LogActionSelection(actionSelected: true, actionInvoked: true, handled: context.IsHandled);
            }
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:54,代码来源:MvcRouteHandler.cs

示例14: GetRoutes

		/// <summary>
		/// Gets the route information
		/// </summary>
		/// <param name="routeData">Raw route data from ASP.NET MVC</param>
		/// <returns>Processed route information</returns>
		public IEnumerable<RouteInfo> GetRoutes(RouteData routeData)
		{
			var routeCollection = routeData.Routers.OfType<RouteCollection>().First();
			for (var i = 0; i < routeCollection.Count; i++)
			{
				var route = routeCollection[i];
				if (route is TemplateRoute)
				{
					yield return ProcessTemplateRoute((TemplateRoute)route);
				}
			}
		}
开发者ID:modulexcite,项目名称:RouteJs,代码行数:17,代码来源:TemplateRouteFetcher.cs

示例15: PrepareRequestAsync

        /// <summary>
        /// Prepares the request.
        /// </summary>
        /// <returns>
        /// Returns false if the request was not successfully prepared
        /// </returns>
        public async Task<bool> PrepareRequestAsync(RouteData routeData)
        {
            // note - at that point the original legacy module did something do handle IIS custom 404 errors
            //   ie pages looking like /anything.aspx?404;/path/to/document - I guess the reason was to support
            //   "directory urls" without having to do wildcard mapping to ASP.NET on old IIS. This is a pain
            //   to maintain and probably not used anymore - removed as of 06/2012. @zpqrtbnk.
            //
            //   to trigger Umbraco's not-found, one should configure IIS and/or ASP.NET custom 404 errors
            //   so that they point to a non-existing page eg /redirect-404.aspx
            //   TODO: SD: We need more information on this for when we release 4.10.0 as I'm not sure what this means.

            //find domain
            //FindDomain();

            // if request has been flagged to redirect then return
            // whoever called us is in charge of actually redirecting
            if (_pcr.IsRedirect)
            {
                return false;
            }

            // set the culture on the thread - once, so it's set when running document lookups
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = _pcr.Culture;

            //find the published content if it's not assigned. This could be manually assigned with a custom route handler, or
            // with something like EnsurePublishedContentRequestAttribute or UmbracoVirtualNodeRouteHandler. Those in turn call this method
            // to setup the rest of the pipeline but we don't want to run the finders since there's one assigned.
            if (_pcr.PublishedContent == null)
            {
                // find the document & template
                await FindPublishedContentAndTemplateAsync(routeData);
            }

            // handle wildcard domains
            //HandleWildcardDomains();

            // set the culture on the thread -- again, 'cos it might have changed due to a finder or wildcard domain
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = _pcr.Culture;

            // trigger the Prepared event - at that point it is still possible to change about anything
            // even though the request might be flagged for redirection - we'll redirect _after_ the event
            //
            // also, OnPrepared() will make the PublishedContentRequest readonly, so nothing can change
            //
            _pcr.OnPrepared();

            // we don't take care of anything so if the content has changed, it's up to the user
            // to find out the appropriate template

            //complete the PCR and assign the remaining values
            return ConfigureRequest();
        }
开发者ID:ryanmcdonough,项目名称:Umbraco9,代码行数:58,代码来源:PublishedContentRequestEngine.cs


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