views:

49

answers:

2

What are extensibility points of URL generation in ASP.NET MVC?

  1. Routes - virtual path depends on it
  2. ???

Addendum 1
Particularily, I need to control not only path part of URL but the host also. And I'd like to embed my generation logics into MVC Framework so that any call to standard Html.ActionLink method would involve my logics. It would be perfect. However, investigating MVC sources I'm desperate to achieve my goal with an easy way.

A: 

Routes is pretty much where it's at. Remember, though, that you can subclass Route and provide your own implementation that does not use key/value URI templates.

There's nothing stopping you from writing your own solution from the ground up, but there's not much point since there's already an extensible foundation for you to work with.

Richard Szalay
Thanks, @Richard, for your attention. However, routing don't give me enough control. See my addendum 1.
Anton
@Anton - There's no reason you couldn't generate absolute URLs from your routes, possibly by including a `siteName` value and looking that up to a domain. Also, I believe you can get access to the host (or at least the raw request) from a custom Route for the parsing aspect.
Richard Szalay
A: 

Routing extensibility points

  • Routes
  • Route constraints
  • Route handlers

In your particular case, you will have to write your own route that will populate additional RouteData items related to host. Parsing your URL will be totally on you.

"{host}/{controller}/{action}"

Maybe also create your custom route handler that will make host parameter mandatory. But that already depends on your particular needs.

Edit

I guess that this article about domain routing may be of some help to you. It looks preety straight forward and uncompicated.

Robert Koritnik
@Robert, writing custom Route, surely, allows me to deal with so called incoming routing. However, outgoing routing is limited to `VirtualPathData`, thus I cannot control the host part of the generated URL. That is the problem!
Anton
I suppose this could be solved using a custom route handler though. But beside that you will have to learn routing thoroughly, because you will probably have to write you own UrlRoutingHandler as well...
Robert Koritnik