ASP.NET MVC routing based on domain and host name

I am new to ASP.NET MVC, most of my experience is with ASP.NET Web formats.

Is there a way to configure routing based on the domain / host name, i.e. www.domain.com goes into one area, admin.domain.com into another, and www.differentdomain.com into another area in a web application.

Also, is there a way to make catch-all ie * .domain.com be redirected to another area?

+6
source share
1 answer

you can use domain routing mapping

routes.Add("DomainRoute", new DomainRoute( "{customer}.example.com", // Domain with parameters "{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults )) 

routing a domain using asp.net mvc

+3
source

Source: https://habr.com/ru/post/978374/


All Articles