How can we make an ASP.NET MVC4 route based on a subdomain?

后端 未结 1 540
谎友^
谎友^ 2021-01-07 14:42

How can we make an ASP.NET MVC4 route that uses subdomain information to determine its route? For example:

website1.domain.com goes to domain.com\

相关标签:
1条回答
  • 2021-01-07 14:57

    ASP.NET's built-in routing doesn't directly support sub-domain routing. But fortunately, there's AttributeRouting, which is a very popular add-on library for routing that allows you to do lots of fancy routing, including sub-domain routing.

    Here's an example from the Attribute Routing site:

    [RouteArea("Users", Subdomain = "users")]
    public class SubdomainController : Controller
    {
        [GET("")]
        public ActionResult Index() { /* ... */ }
    }
    
    0 讨论(0)
提交回复
热议问题