本文整理汇总了C#中Microsoft.AspNet.Routing.RouteContext类的典型用法代码示例。如果您正苦于以下问题:C# RouteContext类的具体用法?C# RouteContext怎么用?C# RouteContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RouteContext类属于Microsoft.AspNet.Routing命名空间,在下文中一共展示了RouteContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Activate_SetsPropertiesFromActionContextHierarchy
public void Activate_SetsPropertiesFromActionContextHierarchy()
{
// Arrange
var httpRequest = Mock.Of<HttpRequest>();
var httpContext = new Mock<HttpContext>();
httpContext.SetupGet(c => c.Request)
.Returns(httpRequest);
httpContext.SetupGet(c => c.RequestServices)
.Returns(Mock.Of<IServiceProvider>());
var routeContext = new RouteContext(httpContext.Object);
var controller = new TestController();
var context = new ActionContext(routeContext, new ActionDescriptor())
{
Controller = controller
};
var activator = new DefaultControllerActivator();
// Act
activator.Activate(controller, context);
// Assert
Assert.Same(context, controller.ActionContext);
Assert.Same(httpContext.Object, controller.HttpContext);
Assert.Same(httpRequest, controller.GetHttpRequest());
}
开发者ID:Nakro,项目名称:Mvc,代码行数:25,代码来源:DefaultControllerActivatorTest.cs
示例2: GetFormInfo
public void GetFormInfo()
{
var protector = new Mock<IDataProtector>();
var protectorProvider = new Mock<IDataProtectionProvider>();
protectorProvider.Setup(x => x.CreateProtector(It.IsAny<string>())).Returns(protector.Object);
var surfaceRouteParams = $"{SurfaceFormHelper.ReservedAdditionalKeys.Controller}=mycontroller&{SurfaceFormHelper.ReservedAdditionalKeys.Action}=myaction&{SurfaceFormHelper.ReservedAdditionalKeys.Area}=myarea";
protector.Setup(dataProtector => dataProtector.Protect(It.IsAny<byte[]>())).Returns(Encoding.UTF8.GetBytes(surfaceRouteParams));
protector.Setup(dataProtector => dataProtector.Unprotect(It.IsAny<byte[]>())).Returns(Encoding.UTF8.GetBytes(surfaceRouteParams));
var helper = new SurfaceFormHelper(Mock.Of<ILoggerFactory>(), protectorProvider.Object);
var request = new Mock<HttpRequest>();
request.Setup(httpRequest => httpRequest.Method).Returns("GET");
request.Setup(httpRequest => httpRequest.Query).Returns(
new FormCollection(new Dictionary<string, StringValues>
{
{"ufprt", Convert.ToBase64String(Encoding.UTF8.GetBytes(surfaceRouteParams))}
}));
var httpCtxAccessor = new Mock<IHttpContextAccessor>();
var httpContext = new Mock<HttpContext>();
httpContext.Setup(context => context.Request).Returns(request.Object);
httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object);
var routeCtx = new RouteContext(httpContext.Object);
var result = helper.GetFormInfo(routeCtx);
Assert.Equal("mycontroller", result.ControllerName);
Assert.Equal("myaction", result.ActionName);
Assert.Equal("myarea", result.Area);
}
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:29,代码来源:SurfaceFormHelperTests.cs
示例3: Activate_PopulatesServicesFromServiceContainer
public void Activate_PopulatesServicesFromServiceContainer()
{
// Arrange
var urlHelper = Mock.Of<IUrlHelper>();
var service = new Mock<IServiceProvider>();
service.Setup(s => s.GetService(typeof(IUrlHelper)))
.Returns(urlHelper);
var httpContext = new Mock<HttpContext>();
httpContext.SetupGet(c => c.RequestServices)
.Returns(service.Object);
var routeContext = new RouteContext(httpContext.Object);
var controller = new TestController();
var context = new ActionContext(routeContext, new ActionDescriptor())
{
Controller = controller
};
var activator = new DefaultControllerActivator();
// Act
activator.Activate(controller, context);
// Assert
Assert.Same(urlHelper, controller.Helper);
}
开发者ID:Nakro,项目名称:Mvc,代码行数:25,代码来源:DefaultControllerActivatorTest.cs
示例4: RouteAsync
public Task RouteAsync(RouteContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
EnsureServices(context.HttpContext);
var actionDescriptor = _actionSelector.Select(context);
if (actionDescriptor == null)
{
_logger.NoActionsMatched();
return TaskCache.CompletedTask;
}
if (actionDescriptor.RouteValueDefaults != null)
{
foreach (var kvp in actionDescriptor.RouteValueDefaults)
{
if (!context.RouteData.Values.ContainsKey(kvp.Key))
{
context.RouteData.Values.Add(kvp.Key, kvp.Value);
}
}
// Removing RouteGroup from RouteValues to simulate the result of conventional routing
context.RouteData.Values.Remove(TreeRouter.RouteGroupKey);
}
context.Handler = (c) => InvokeActionAsync(c, actionDescriptor);
return TaskCache.CompletedTask;
}
开发者ID:phinq19,项目名称:git_example,代码行数:33,代码来源:MvcRouteHandler.cs
示例5: 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
示例6: RouteAsync
public async Task RouteAsync(RouteContext context)
{
if (IsValidRequest(context.HttpContext))
{
try
{
// Store the requested targetted action so that the OrchardMiddleware
// can continue with it once the tenant pipeline has been executed
if (_pipeline != null)
{
context.HttpContext.Items["orchard.Handler.Target"] = _target;
context.HttpContext.Items["orchard.Handler.RouteContext"] = context;
await _pipeline.Invoke(context.HttpContext);
}
else
{
await _target.RouteAsync(context);
}
}
catch (Exception ex)
{
var logger = context.HttpContext.ApplicationServices.GetService<ILogger<TenantRoute>>();
logger.LogError("Error occured serving tenant route", ex);
throw;
}
}
}
开发者ID:adwardliu,项目名称:Orchard2,代码行数:29,代码来源:TenantRoute.cs
示例7: Invoke
public async Task Invoke(HttpContext httpContext)
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Begin Routing Request");
}
var shellSettings = httpContext.RequestServices.GetService<ShellSettings>();
var routerTable = httpContext.ApplicationServices.GetService<IRunningShellRouterTable>();
var router = routerTable.GetOrAdd(
shellSettings.Name,
name => httpContext.RequestServices.GetService<IRouteBuilder>().Build()
);
var context = new RouteContext(httpContext);
context.RouteData.Routers.Add(router);
await router.RouteAsync(context);
if (!context.IsHandled)
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Request did not match any routes.");
}
await _next.Invoke(httpContext);
}
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("End Routing Request");
}
}
开发者ID:mzgnr,项目名称:Orchard2,代码行数:35,代码来源:OrchardRouterMiddleware.cs
示例8: 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
示例9: RouteAsync
public async Task RouteAsync(RouteContext context)
{
var request = context.HttpContext.Request;
Uri uri;
PathString remaining;
if (!request.Path.StartsWithSegments(PathString.FromUriComponent("/" + _routePrefix), out remaining))
{
// Fallback to other routes.
return;
}
uri = new Uri(remaining.ToString(), UriKind.Relative);
context.HttpContext.ODataProperties().Model = _model;
var parser = new ODataUriParser(_model, uri);
var path = parser.ParsePath();
context.HttpContext.ODataProperties().NewPath = path;
context.HttpContext.ODataProperties().Path =
context.HttpContext.ODataPathHandler().Parse(_model, "http://service-root/", remaining.ToString());
context.HttpContext.ODataProperties().IsValidODataRequest = true;
await m.RouteAsync(context);
context.IsHandled = true;
}
开发者ID:emreolgun,项目名称:WebApi,代码行数:25,代码来源:ODataRoute.cs
示例10: 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
示例11: RouteAsync
public async Task RouteAsync(RouteContext context)
{
context.RouteData.Values["controller"] = context.RouteData.Values["controller"].ToString().Replace("-", "_");
context.RouteData.Values["action"] = context.RouteData.Values["action"].ToString().Replace("-", "_");
await _target.RouteAsync(context);
}
开发者ID:al-main,项目名称:ui-for-aspnet-mvc-6-demos,代码行数:8,代码来源:HyphenatedRouteHandler.cs
示例12: RouteAsync
public async Task RouteAsync(RouteContext context) {
if (context.HttpContext.Request.Host.Value == _urlHost) {
context.HttpContext.Items["orchard.Handler"] = new Func<Task>(async () => {
await _target.RouteAsync(context);
});
await _pipeline.Invoke(context.HttpContext);
}
}
开发者ID:jefth,项目名称:OrchardNoCMS,代码行数:9,代码来源:TenantRoute.cs
示例13: RouteAsync
public async Task RouteAsync(RouteContext context)
{
context.RouteData.Routers.Add(_next);
var locale = GetLocale(context.HttpContext) ?? "en-US";
context.RouteData.Values.Add("locale", locale);
await _next.RouteAsync(context);
}
开发者ID:phinq19,项目名称:git_example,代码行数:9,代码来源:LocalizedRoute.cs
示例14: SelectAsync
public async Task<ActionDescriptor> SelectAsync(RouteContext context)
{
if (context.HttpContext.ODataProperties().IsValidODataRequest)
{
return await Task.FromResult(_convention.SelectAction(context));
}
return await _selector.SelectAsync(context);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:9,代码来源:ODataActionSelector.cs
示例15: RouteAsync
public async Task RouteAsync(RouteContext context)
{
var name = context.RouteData.Values["name"] as string;
if (String.IsNullOrEmpty(name))
{
return;
}
await context.HttpContext.Response.WriteAsync($"Hi {name}!");
context.IsHandled = true;
}
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:10,代码来源:HelloRouter.cs
示例16: IsValidForRequest
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
{
if(routeContext.HttpContext.Request.Method != "POST")
{
return false;
}
var value = routeContext.HttpContext.Request.Form[_submitButtonName];
return !string.IsNullOrEmpty(value);
}
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:10,代码来源:FormValueRequiredAttribute.cs
示例17: Invoke
public async Task Invoke(HttpContext httpContext)
{
var context = new RouteContext(httpContext);
context.RouteData.Routers.Add(_router);
await _router.RouteAsync(context);
if (!context.IsHandled)
{
_logger.LogVerbose("Request did not match any routes.");
await _next(httpContext);
}
}
开发者ID:kyrylovych,项目名称:zstu-docs,代码行数:11,代码来源:ExtendedRouterMiddleware.cs
示例18: Invoke
public async Task Invoke(HttpContext httpContext)
{
var rcontext = new RouteContext(httpContext);
rcontext.RouteData.Routers.Add(_router);
await _router.RouteAsync(rcontext);
if (!rcontext.IsHandled)
{
await _next.Invoke(httpContext);
}
}
开发者ID:sshibani,项目名称:dd4t-vnext,代码行数:12,代码来源:DD4TMiddleWare.cs
示例19: IsValidForRequest
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
{
if (routeContext.RouteData.Values.ContainsKey(Name))
return false;
if (routeContext.RouteData.DataTokens.ContainsKey(Name))
return false;
if (routeContext.HttpContext.Request.Query.ContainsKey(Name))
return false;
return true;
}
开发者ID:qbikez,项目名称:Odachi,代码行数:13,代码来源:NoRequestValueAttribute.cs
示例20: GetFormInfo
/// <summary>
/// Checks the request and query strings to see if it matches the definition of having a Surface controller
/// posted/get value, if so, then we return a PostedDataProxyInfo object with the correct information.
/// </summary>
/// <param name="routeContext"></param>
/// <returns></returns>
public RouteDefinition GetFormInfo(RouteContext routeContext)
{
if (routeContext == null) throw new ArgumentNullException(nameof(routeContext));
if (routeContext.HttpContext == null) throw new ArgumentNullException(nameof(routeContext) + ".HttpContext");
if (routeContext.HttpContext.Request == null) throw new ArgumentNullException(nameof(routeContext) + ".HttpContext.Request");
var encodedVal = GetRequestSurfaceToken(routeContext.HttpContext.Request);
if (string.IsNullOrWhiteSpace(encodedVal)) return null;
string decryptedString;
try
{
decryptedString = Encoding.UTF8.GetString(_dataProtector.Unprotect(Convert.FromBase64String(encodedVal)));
}
catch (CryptographicException)
{
_logger.LogWarning("A value was detected in the ufprt parameter but Umbraco could not decrypt the string");
return null;
}
var parsedQueryString = QueryHelpers.ParseQuery(decryptedString);
var decodedParts = new Dictionary<string, string>();
foreach (var key in parsedQueryString.Keys)
{
decodedParts[key] = parsedQueryString[key];
}
//validate all required keys exist
var isValid = ValidateRequiredTokenParams(decodedParts);
if (isValid == false) return null;
foreach (var item in decodedParts.Where(x => new[] {
ReservedAdditionalKeys.Controller,
ReservedAdditionalKeys.Action,
ReservedAdditionalKeys.Area }.Contains(x.Key) == false))
{
// Populate route with additional values which aren't reserved values so they eventually to action parameters
routeContext.RouteData.Values[item.Key] = item.Value;
}
//return the proxy info without the surface id... could be a local controller.
return new RouteDefinition
{
ControllerName = WebUtility.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Controller).Value),
ActionName = WebUtility.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Action).Value),
Area = WebUtility.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Area).Value),
};
}
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:57,代码来源:SurfaceFormHelper.cs
注:本文中的Microsoft.AspNet.Routing.RouteContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论