2016-06-07 18 views
0

我已經創建了一個解決方案,並將四個項目添加到其中。
包含三個mvc站點(SiteA,SiteB,SiteC) 和一個公共核心類庫(名稱是核心項目)。 現在所有的mvc站點的控制器都被移到了核心項目中。 我將核心項目引用到這些mvc站點。 我嘗試在這些網站註冊路線。如何限制動作在特定命名空間中的動作?

站點A:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     routes.MapRoute(
      name: "AWebDefault", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      namespaces: new string[] { "Core.AWeb.Controllers" } 
     ); 

網站B:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     routes.MapRoute(
      name: "BWebDefault", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      namespaces: new string[] { "Core.BWeb.Controllers" } 
     );  

思泰科:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     routes.MapRoute(
      name: "CWebDefault", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
      namespaces: new string[] { "Core.CWeb.Controllers" } 
     );  

的問題是: 當我訪問的站點A,以及如何防止用戶vistit siteB控制器或SiteC控制器? 我想要的控制器只能在特殊命名空間中找到。無法在其他名稱空間中搜索。那麼如何解決呢?

回答

0

您可以創建action filtercustom action filter並在動作或控制器之前使用它。爲此商店命名空間名稱和檢入篩選器。如果目標操作的命名空間與命名空間名稱相同,則允許訪問。另一個解決方案是使用Area。要生成指向不同區域的鏈接,您必須明確傳遞這些方法的routeValues參數中的目標區域名稱(Linking Between Areas)。

相關問題