1

我花了一整天的时间试图让现有的 MVC 应用程序工作。

我有以下情况:

1) 我开始使用自定义区域处理现有的 ASP.Net MVC 应用程序

2)它在办公室工作得很好

3) 我在家,我通过 VPN 获得了 TFS 的最新代码

4)它正在成功构建,但如果我尝试从 Visual Studio 2012 中运行它,它看不到注册区域

HTTP 404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下内容

URL 并确保拼写正确。

未为请求的 URL 配置默认文档,并且未在服务器上启用目录浏览。

5) 我创建了一个普通的 MVC 网站 (NO AreaRegistrations) 并在 Visual Studio 2012 中运行它,它没有给出错误

6)我已经尝试过RouteDebugger,但我不断收到以下错误:

序列不包含任何元素

我也被困在试图解决这个问题。如果有另一种方法可以实际进入它以查看它失败的地方,那将有所帮助。

在实际的区域文件夹中: MyProject\Areas\MyCustomArea 我有

MyProject\Areas\MyCustomArea\AreaRegistration.cs:

using Mvc = System.Web.Mvc;

    namespace MyProject.Areas.MyCustom
    {
        public class AreaRegistration : Mvc.AreaRegistration
        {
            public override string AreaName
            {
                get { return "MyCustomArea"; }
            }

            public override void RegisterArea(Mvc.AreaRegistrationContext context)
            {
                RouteConfig.RegisterRoutes(context);
            }
        }
    }

MyProject\Areas\MyCustomArea\RouteConfig.cs

using System.Web.Mvc;
using System.Web.Optimization; // <-- DOES THIS REFERENCE HAVE AN IMPACT?

namespace MyProject.Areas.MyCustomArea
{
    public class RouteConfig
    {
        public static void RegisterRoutes(AreaRegistrationContext context)
        {

            context.MapRoute(
                "MyCustomArea_Default",
                "MyCustomArea/{controller}/{action}/{id}",
                defaults: new { action = "Index", id = UrlParameter.Optional },
                namespaces: new[] { "MyProject.Areas.MyCustomArea.Controllers" });
        }
    }
}

我的 App_Start 文件夹没有 Route.config.cs文件

我有一个MyProject\packages.config具有以下内容:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="RazorGenerator.Mvc" version="2.2.2" targetFramework="net45" />
  <package id="WebActivatorEx" version="2.0.5" targetFramework="net45" />
</packages>

我使用 System.Web.Optimization

我的Web.config文件具有以下内容:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="Kendo.Mvc.UI" />
      </namespaces>
    </pages>
  </system.web>

我可能需要做些什么来让它工作,记住它在工作中工作,我使用 RazorGenerator 以及 Web 优化,如果这些有影响

对不起,如果它太长了

4

1 回答 1

3

确保AreaRegistration.RegisterAllAreas()在您的应用程序启动时调用它。通常的位置Application_Start在 global.asax 中。

于 2014-03-21T16:40:09.213 回答