本文整理汇总了C#中Microsoft.AspNet.Routing.RouteData类的典型用法代码示例。如果您正苦于以下问题:C# RouteData类的具体用法?C# RouteData怎么用?C# RouteData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RouteData类属于Microsoft.AspNet.Routing命名空间,在下文中一共展示了RouteData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: AfterAction
public static void AfterAction(
this DiagnosticSource diagnosticSource,
ActionDescriptor actionDescriptor,
HttpContext httpContext,
RouteData routeData)
{
if (diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterAction"))
{
diagnosticSource.Write(
"Microsoft.AspNet.Mvc.AfterAction",
new { actionDescriptor, httpContext = httpContext, routeData = routeData });
}
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:13,代码来源:MvcRouteHandlerDiagnosticSourceExtensions.cs
示例17: EmptyResult_ExecuteResult_IsANoOp
public void EmptyResult_ExecuteResult_IsANoOp()
{
// Arrange
var emptyResult = new EmptyResult();
var httpContext = new Mock<HttpContext>(MockBehavior.Strict);
var routeData = new RouteData();
var actionDescriptor = new ActionDescriptor();
var context = new ActionContext(httpContext.Object, routeData, actionDescriptor);
// Act & Assert (does not throw)
emptyResult.ExecuteResult(context);
}
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:14,代码来源:EmptyResultTests.cs
示例18: GetNameFromRouteContext
private string GetNameFromRouteContext(RouteData routeData)
{
string name = null;
if (routeData.Values.Count > 0)
{
var routeValues = routeData.Values;
object controller;
routeValues.TryGetValue("controller", out controller);
string controllerString = (controller == null) ? string.Empty : controller.ToString();
if (!string.IsNullOrEmpty(controllerString))
{
name = controllerString;
object action;
routeValues.TryGetValue("action", out action);
string actionString = (action == null) ? string.Empty : action.ToString();
if (!string.IsNullOrEmpty(actionString))
{
name += "/" + actionString;
}
if (routeValues.Keys.Count > 2)
{
// Add parameters
var sortedKeys = routeValues.Keys
.Where(key =>
!string.Equals(key, "controller", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(key, "action", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(key, AttributeRouting.RouteGroupKey, StringComparison.OrdinalIgnoreCase))
.OrderBy(key => key, StringComparer.OrdinalIgnoreCase)
.ToArray();
if (sortedKeys.Length > 0)
{
string arguments = string.Join(@"/", sortedKeys);
name += " [" + arguments + "]";
}
}
}
}
return name;
}
开发者ID:jango2015,项目名称:ApplicationInsights-aspnet5,代码行数:47,代码来源:OperationNameTelemetryInitializer.cs
示例19: HttpStatusCodeResult_ExecuteResultSetsResponseStatusCode
public void HttpStatusCodeResult_ExecuteResultSetsResponseStatusCode()
{
// Arrange
var result = new HttpStatusCodeResult(StatusCodes.Status404NotFound);
var httpContext = new DefaultHttpContext();
var routeData = new RouteData();
var actionDescriptor = new ActionDescriptor();
var context = new ActionContext(httpContext, routeData, actionDescriptor);
// Act
result.ExecuteResult(context);
// Assert
Assert.Equal(StatusCodes.Status404NotFound, httpContext.Response.StatusCode);
}
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:17,代码来源:HttpStatusCodeResultTests.cs
示例20: RouteUmbracoContentAsync
internal async Task<bool> RouteUmbracoContentAsync(UmbracoContext umbCtx, PublishedContentRequest pcr, RouteData routeData)
{
//Initialize the context, this will be called a few times but the initialize logic
// only executes once. There might be a nicer way to do this but the RouteContext and
// other request scoped instances are not available yet.
umbCtx.Initialize(pcr);
//Prepare the request if it hasn't already been done
if (pcr.IsPrepared == false)
{
if (await pcr.PrepareAsync(routeData))
{
if (umbCtx.HasContent == false) return false;
}
}
return umbCtx.HasContent;
}
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:17,代码来源:UmbracoRouter.cs
注:本文中的Microsoft.AspNet.Routing.RouteData类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论