Houshang.Karami
Houshang.Karami

Reputation: 179

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

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?

Upvotes: 0

Views: 2257

Answers (1)

Eilon
Eilon

Reputation: 25704

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() { /* ... */ }
}

Upvotes: 2

Related Questions