0

I am trying to create one .NET Core MVC app that serves up different content (that i defined as areas) based on the domain. I am using a constraint that will serve up the appropriate area based on the domain:

routes.MapRoute(
    name: "Website1",
    template: "{controller=Default}/{action=Index}/{id?}",
    defaults: new { area = "Website1" },
    constraints: new { _ = new DomainConstraint("website1.com") });

routes.MapRoute(
    name: "Website2",
    template: "{controller=Default}/{action=Index}/{id?}",
    defaults: new { area = "Website2" },
    constraints: new { _ = new DomainConstraint("website2.com") });

That is working well (will ommit DomainConstraint because that is working), but the problem is I have 2 different controllers using the same route and I am getting this error:

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

Company.Web.Mvc.Sites.Areas.Website1.DefaultController.ThankYou Company.Web.Mvc.Sites.Areas.Website2.DefaultController.ThankYou

both those controllers have the following route attributre (different sites will have the same url sometimes no doubt):

[Route("thank-you")]

My question is, how can I make sure than when the correct area is matched (Website1, for example),the request is routed to that area's controller (Website1.DefaultController) route (thank-you)? I tried creating a namespace contstraint that inherits from ActionMethodSelectorAttribute but that does not work for route attributes apparently.

Basically I need two different domains to be able to use the same url that would be in two different controllers:

website1.com/thank-you
(Company.Web.Mvc.Sites.Areas.Website1.DefaultController.ThankYou)

website2.com/thank-you 
(Company.Web.Mvc.Sites.Areas.Website2.DefaultController.ThankYou)

Thank you very much in advance :)

Aymen TAGHLISSIA
  • 1,675
  • 13
  • 30
user9871834
  • 73
  • 1
  • 4

0 Answers0