标签:
添加Areas主要目的是区分一些不同的业务,避免不同的业务都在同一个Controllers下造成混乱,在MVC项目上右键->添加区域->我添加了HMbolie和PClient两个区域->如下图HMbolieAreaRegistration.cs和PClientAreaRegistration.cs是默认生成的,代码中的第四个参数是 string[] namespaces命名空间参数。
{
public class HMbolieAreaRegistration : AreaRegistration
{ public override string AreaName { get { return"HMbolie";
} } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "HMbolie_default", "HMbolie/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, new string[] { "Demo.Areas.HMbolie.Controllers" } ); } }
} namespace Demo.Areas.PClient { public class PClientAreaRegistration : AreaRegistration { public override string AreaName { get { return "PClient"; } }
public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "PClient_default", "PClient/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, new string[] { "Demo.Areas.PClient.Controllers" } ); } } }
/// <summary> /// ApplicationStart /// </summary> protected void Application_Start() { //System.Threading.Thread.Sleep(10000); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); }
我在Start()中线程睡10s中才启动,断点调试发现AreaRegistration.RegisterAllAreas()中根本没有找到HMbolieAreaRegistration.cs和PClientAreaRegistration.cs这两个相关的Areas类,iis下的代码是最新部署,但是却不执行?
解决方法如下:删除iis缓存文件
标签:
原文地址:http://www.cnblogs.com/ligl/p/5162335.html