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

2019-02-16 04:29发布

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\websites\1

website2.domain.com goes to domain.com\websites\2

This is a dynamic mapping like this: websiteN.domain.com goes to domain.com\websites\N

I have a username parameter,How Can I pass through controller/action?

1条回答
乱世女痞
2楼-- · 2019-02-16 04:39

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() { /* ... */ }
}
查看更多
登录 后发表回答