AreaRegistration.RegisterAllAreas() 不是区域注册规则 [英] AreaRegistration.RegisterAllAreas() is not Registering Rules For Area

查看:34
本文介绍了AreaRegistration.RegisterAllAreas() 不是区域注册规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MVC 4 Web 应用程序,其中包含一些区域.我对名为目录"的区域的路由规则有问题.RouteConfig.cs 文件是:

I have an MVC 4 web application which consists some areas. I have a problem with the routing rules of an area named "Catalog". The RouteConfig.cs file is:

    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 如下:

and Global.asax as follows:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

CatalogAreaRegistration 是这样的:

And CatalogAreaRegistration is something like this:

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 中的规则.

The problem is when i debug, RouteCollection routes does not include rules that are defined in the area. I used routedebugger and saw that routes collection does not consists rules of "Catalog" area. It has only rules in the RouteConfig.

我不知道是什么问题.提前致谢.

I have no idea what is the problem. Thanks in advance.

推荐答案

我认为由于 Visual Studio 的缓存,一些 dll 没有正确编译,这种情况可能会发生.如果这样做,请删除以下位置的所有临时文件:

I think due to Visual Studio's caching, some of the dll's aren't compiled properly and this situation can happen. If you do, delete all temp files from following locations:

  • C:Temp
  • C:Users\%Username%AppDataLocalMicrosoftVisualStudio
  • C:WindowsMicrosoft.NETFrameworkv4.0.30319ASP.NET 临时文件
  • C:WindowsMicrosoft.NETFramework64v4.0.30319ASP.NET 临时文件
  • PathToYourProjectobjDebug

更新:

  • AppDataLocalTempTemporary ASP.NET 文件

然后重新启动 Visual Studio.我就是这样解决的.

Then restart the Visual Studio. This is how i resolved.

这篇关于AreaRegistration.RegisterAllAreas() 不是区域注册规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆