我有以下控制器:
我只需要部署或发布销售和采购控制器。我该如何只部署那些?
答案 0 :(得分:1)
好。你不能。您项目中的所有控制器都包含在部署中。
您可以做的是删除默认路由并创建两个特定路由,每个路由对应您要启用的每个控制器。
首先,找到默认路线:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters*
new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
注释然后创建特定路线:
routes.MapRoute(
"Sales", // Route name
"sales/{action}/{id}", // URL with parameters*
new { controller = "Sales", action = "Index",
id = UrlParameter.Optional }
);
routes.MapRoute(
"Purchase", // Route name
"purchase/{action}/{id}", // URL with parameters*
new { controller = "Purchase", action = "Index",
id = UrlParameter.Optional }
);
答案 1 :(得分:0)
除了为这些控制器创建特定路线之外,更简单的方法是阻止您不希望通过IgnoreRoute
访问的路线。
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Block the controllers under development so they
// cannot be accessed.
routes.IgnoreRoute("accounts/{*pathInfo}");
routes.IgnoreRoute("hr/{*pathInfo}");
routes.IgnoreRoute("settings/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}