我已经创建了一个解决方案,并将四个项目添加到其中。
它包含三个mvc站点( SiteA、SiteB、SiteC)和一个公共核心类库(名称为核心项目)。现在,所有mvc站点的控制器都移到了核心项目中。我将核心项目引用到这些mvc站点。我尝试在这些站点中注册路由。
SiteA:
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" }
); SiteB:
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" }
); SiteC:
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" }
); 问题是:当我访问siteA时,如何防止用户访问siteB控制器或SiteC控制器?我想要的控制器只能在特殊的命名空间中找到。无法在其他命名空间中搜索。那么该如何解决呢?
发布于 2016-06-07 14:12:17
您可以创建action filter或custom action filter,并在操作或控制器之前使用它。对于此存储命名空间名称和签入筛选器。如果目标操作命名空间与命名空间名称相同,则允许访问。另一个解决方案是使用Area。要生成到其他区域的链接,必须在这些方法的routeValues参数中显式传递目标区域名称(Linking Between Areas。
https://stackoverflow.com/questions/37670279
复制相似问题