Breaking String URL into Route Data ASP.NET MVC

Getting your route data into URL format is easy – simply use the UrlHelper (Url.Action). But reversing this, and parsing a URL is a bit more fiddly: string path = “”; string queryString = “”; System.Web.Routing.RouteData routeFromUrl = System.Web.Routing.RouteTable.Routes.GetRouteData(new HttpContextWrapper(new HttpContext(new HttpRequest(null, new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, path).ToString(), queryString), new HttpResponse(new System.IO.StringWriter())))); You can then use … More Breaking String URL into Route Data ASP.NET MVC