How to parse string url in MVC route values ​​(scope, controller, action, request)?

Is there a way to retrieve a scope, controller, action, and request from a URL in ASP.NET MVC? Do not want to invent a wheel that implements my own, if there is a way to do it.

Thanks!

+7
url parsing asp.net-mvc asp.net-mvc-2
source share
2 answers

I managed to get it from here:

String URL in RouteValueDictionary

To get the scope from this example, I used:

line area = routeData.DataTokens ["area"]. ToString ();

+6
source share

You can extract this information from the routes:

var controller = RouteData.Values["controller"]; var action = RouteData.Values["action"]; var action = RouteData.Values["area"]; 

As for the query string, you can pull it out of the query:

 var queryString = Request.Url.Query; 

UPDATE:

If the URL comes from the database:

 var uri = new Uri(someStringThatRepresentsTheUrlAndComesFromADb); var queryString = uri.Query; 
-2
source share

All Articles