I have many host names on IIS that point to the same ASP.NET MVC app.
www.domain.com
www.domain.co.uk
www.domain.net
...
How can I get the top level domain (es. “.com”) when I set a map route like the following?
Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
' MapRoute takes the following parameters, in order:
' (1) Route name
' (2) URL with parameters
' (3) Parameter defaults
routes.MapRoute( _
"Default", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)
End Sub
You need to create a custom route. Just inherit
Route, overrideGetRouteDataand include routing information which is for the TLD.http://msdn.microsoft.com/en-us/library/system.web.routing.route.getroutedata.aspx
Example
The route:
Mapping it in global.asax:
And accessing the parameter in the controller: