2

So my MVC application gets a request from a user who has just browsed to e.g. /home/about. It checks the RouteTable for a matching pattern and dispatches it to the correct Controller and Action. Great.

What if I want to take over that function? I don't want to rewrite the URL, I don't want to mess with the RouteData property in a filter context or anything like that. I want to take over the part where route X gets translated to controller Y and action Z by my MVC application. Something like MyRouteResolver : IRouteResolver (if that actually existed).

I have been digging around on MSDN but I can't find any hint on where this is done. Any help is appreciated.

1 Answer 1

2

You could write an http handler / module that effectively does the same thing, look at System.Web.Routing.UrlRoutingHandler to see how they do it.

One problem however, is that all the calls within MVC to find the url for a route wouldn't work (eg UrlHelper), they are all hardcoded to grab the static route collection. You could fill that route collection to make it work, but then I'm not sure what you're gaining from having your ow routing handler.

The current routing handler is fairly flexible, you maybe be able to write your own route classes (see RouteBase) instead of replacing the entire handler.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.