Question

I am currently involved in a new MVC 5 project an looking to map domains to MVC areas.

For example the following sites should map the their areas:

www.sitea.com needs to map to area SiteA
www.siteB.com needs to map to area SiteB
www.siteC.com needs to map to area SiteC

Is there an easier way to do this in MVC 5 using attribute mapping, or does one still need to look at using something similar to the IRouteConstraint interface

Thanks in advance for the assistance.

Regards

Était-ce utile?

La solution

If you mean attribute routing, unfortunately not. The purpose of introducing attribute routing in MVC 5 is to co-locate routing configuration with controller's actions to ease reasoning about mapping between URI's and actions.

The new functionality of attribute routing still revolves around VirtualPathData class, which constrains you to use tokens only from the virtual path. Mapping hostname to area exceeds boundary of declarative routing even in MVC 5 and you would have to extend infrastructure in a solution close to Implementing ASP.NET MVC Domain Routing by Maarten Balliauw.

You could of course try to inherit from RouteAttribute, RouteAreaAttribute and the like but IMHO you would end up at implementation similar to above.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top