C# 在MVC4.0中,将整个URL作为参数
可能重复:C# 在MVC4.0中,将整个URL作为参数,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,可能重复: 我的URL看起来像 http://Infosys-1234.teradata.com 我可以通过将路径配置为以下方式将整个URL作为参数: routes.MapRoute( name: "Default", url: "{url}", defaults: new { controller = "App", action = "GetDetailsById",
我的URL看起来像
http://Infosys-1234.teradata.com
我可以通过将路径配置为以下方式将整个URL作为参数:
routes.MapRoute(
name: "Default",
url: "{url}",
defaults: new { controller = "App",
action = "GetDetailsById",
// url = UrlParameter.Optional
}
);
如果没有,建议我一个替代方案。我想从url中取出Infosys-1234作为参数
routes.Add("DomainRoute", new DomainRoute(
"{param1}.example.com", "{action}/{param1}",
new { controller = "Home", action = "Index", param1 = "" } // Parameter defaults
));
从
编辑:需要改为说param1(参数名称)
如果这不起作用,也许这是一个更好的解决方案
routes.MapRoute(
name: "Default",
url: "{param1}.mydomain.com",
defaults: new { controller = "App",
action = "GetDetailsById",
param1 = ""
}
);