【问题标题】:MVC Routes for an multi tenant application多租户应用程序的 MVC 路由
【发布时间】:2014-10-03 14:46:22
【问题描述】:

我有一个 MVC 应用程序,但无法让路由为我的多租户应用程序工作。问题来了:

我的应用程序中有 2 种类型的页面,大多数要求租户名称在 url 中,但有些不需要。例如

这些都做(租户名称是这些例子是三星和苹果):

http://www.mytestapp.com/samsung/customers/add

http://www.mytestapp.com/apple/customers/add

这些不要:

http://www.mytestapp.com/home/register/

http://www.mytestapp.com/home/aboutus/

我需要哪些路线才能使其正常工作?我已经尝试过了,但它不适用于注册和关于我们的页面。

            routes.MapRoute(
            name: "TenantRoute",
            url: "{tenantid}/{controller}/{action}/{id}",
            defaults: new { tenantid = "tenantname", controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 routes


    【解决方案1】:

    好吧,您需要第二条路线来匹配非租户路线。如果registeraboutus 是具有Index 操作的控制器,则默认值应该匹配:

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

    【讨论】:

      【解决方案2】:

      试试这个

         routes.MapRoute(
                  "samsung",
                  "samsung/{controller}/{action}/{id}",
                 new { controller = "YourController", action = "YourAction", id = UrlParameter.Optional}
              );
      
              routes.MapRoute(
                  "apple",
                  "apple/{controller}/{action}/{id}",
                  new { controller = "YourController", action = "YourAction", id = UrlParameter.Optional }
              );
        routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Register", action = "Index", id = UrlParameter.Optional }
          );
      

      【讨论】:

        猜你喜欢
        • 2016-12-12
        • 2012-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-09
        • 1970-01-01
        相关资源
        最近更新 更多