.Net Core : How to get RouteData from URL string?

Viewed 1174

In a .Net core Controller, I would like to parse a custom URL (string) to get its routeDatas.

In .Net 4.5 this code do the job. What is the equivalent in .Net Core ?

var routeData = System.Web.Routing.RouteTable.Routes.GetRouteData(
    new HttpContextWrapper(
        new HttpContext(
            new HttpRequest(null, link.Url, ""), 
            new HttpResponse(new System.IO.StringWriter())
        )
    )
)
2 Answers

You can access it from RouteData property in ControllerBase and its sub-class.

Edit:

Okay, then you can take a look at this question.

Depending on your scenario, you maybe want to handle the parameter in a different way.

Related