我们怎样才能使基于子域的ASP.NET MVC4路线? [英] How can we make an ASP.NET MVC4 route based on a subdomain?
问题描述
我们怎样才能使使用子域名信息来确定其路由的ASP.NET MVC4路线?例如:
How can we make an ASP.NET MVC4 route that uses subdomain information to determine its route? For example:
website1.domain.com
进入 domain.com \\网站\\ 1
website2.domain.com
进入 domain.com \\网站\\ 2
这是一个像这样的动态映射: websiteN.domain.com
进入 domain.com \\网站\\ n
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?
推荐答案
ASP.NET内置的路由不直接支持子域路由。但幸运的是,有 AttributeRouting ,这是一个非常受欢迎的附加库路由,允许你做很多花哨的路由包括子域路由。
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() { /* ... */ }
}
这篇关于我们怎样才能使基于子域的ASP.NET MVC4路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!