Asp.net-Mvc
AreaRegistration.RegisterAllAreas() 不是區域註冊規則
我有一個包含一些區域的 MVC 4 Web 應用程序。我對名為“目錄”的區域的路由規則有疑問。RouteConfig.cs 文件是:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, ); }和 Global.asax 如下:
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }CatalogAreaRegistration 是這樣的:
public class CatalogAreaRegistration : AreaRegistration { public override string AreaName { get { return "Catalog"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Catalog_default", "Catalog/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); } }問題是當我調試時,RouteCollection 路由不包含該區域中定義的規則。我使用了 routedebugger,發現路由集合不包含“目錄”區域的規則。它只有 RouteConfig 中的規則。
我不知道是什麼問題。提前致謝。
我認為由於 Visual Studio 的記憶體,一些 dll 沒有正確編譯,這種情況可能會發生。如果這樣做,請從以下位置刪除所有臨時文件:
- C:\溫度
- C:\Users%Username%\AppData\Local\Microsoft\VisualStudio
- C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET 文件
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319\臨時 ASP.NET 文件
- Path\To\Your\Project\obj\Debug
更新 :
- AppData\Local\Temp\Temporary ASP.NET 文件
然後重新啟動 Visual Studio。我就是這樣解決的。