可能重复:
Is it possible to make an ASP.NET MVC route based on a subdomain?
我的网址看起来像
http://Infosys-1234.teradata.com
我可以将路径配置为:
,将整个网址作为参数 routes.MapRoute(
name: "Default",
url: "{url}",
defaults: new { controller = "App",
action = "GetDetailsById",
// url = UrlParameter.Optional
}
);
如果没有,建议我另类。我想从网址中取出Infosys-1234作为参数。
答案 0 :(得分:0)
routes.Add("DomainRoute", new DomainRoute(
"{param1}.example.com", "{action}/{param1}",
new { controller = "Home", action = "Index", param1 = "" } // Parameter defaults
));
从 http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx
编辑:需要改为说param1(参数名称)
如果这不起作用,这可能是一个更好的解决方案
routes.MapRoute(
name: "Default",
url: "{param1}.mydomain.com",
defaults: new { controller = "App",
action = "GetDetailsById",
param1 = ""
}
);