// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Routing { /// /// Extension methods for related to routing. /// public static class RoutingHttpContextExtensions { /// /// Gets the associated with the provided . /// /// The associated with the current request. /// The , or null. public static RouteData GetRouteData(this HttpContext httpContext) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } var routingFeature = httpContext.Features[typeof(IRoutingFeature)] as IRoutingFeature; return routingFeature?.RouteData; } /// /// Gets a route value from associated with the provided /// . /// /// The associated with the current request. /// The key of the route value. /// The corresponding route value, or null. public static object GetRouteValue(this HttpContext httpContext, string key) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } var routingFeature = httpContext.Features[typeof(IRoutingFeature)] as IRoutingFeature; return routingFeature?.RouteData.Values[key]; } } }