When using ASP.Net routing, how can you get the RouteData from the code-behind?
I know you can get it from the GetHttpHander method of the RouteHandler (you get handed the RequestContext), but can you get this from the code-behind?
Is there anything like...
RequestContext.Current.RouteData.Values["whatever"];
...that you can access globally, like you can do with HttpContext?
Or is it that RouteData is only meant to be accessed from inside the RouteHandler?
RouteData is an attribute of the basic Controller class, so you can access RouteData in any controller. RouteData contains routing information for the current request. You can use RouteData to get controller, operation or parameter information as shown below.
As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web API. For example, you can easily create URIs that describe hierarchies of resources. The earlier style of routing, called convention-based routing, is still fully supported.
You could also use the following:
//using System.Web; HttpContext.Current.Request.RequestContext.RouteData
You can use the following:
RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With