【问题标题】:Take whole URL as parameter in MVC 4.0 [duplicate]将整个 URL 作为 MVC 4.0 中的参数 [重复]
【发布时间】:2012-11-12 22:57:34
【问题描述】:

可能重复:
Is it possible to make an ASP.NET MVC route based on a subdomain?

我的网址看起来像

    http://Infosys-1234.teradata.com

我可以通过将路径配置为将整个 URL 作为参数:

         routes.MapRoute(
    name: "Default",
    url: "{url}",
    defaults: new { controller = "App",
                    action = "GetDetailsById", 
                   // url = UrlParameter.Optional
                  }
           );

如果没有,请给我一个替代方案。我想从url中取出Infosys-1234作为参数。

【问题讨论】:

标签: c# asp.net-mvc-4


【解决方案1】:
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 = ""
                  }
           );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 2023-03-24
    • 2011-01-01
    • 2014-08-25
    相关资源
    最近更新 更多