簡體   English   中英

ASP.Net MVC 4未注冊的區域。 Visual Studio 2012中的HTTP 404錯誤

[英]ASP.Net MVC 4 Areas not registering. HTTP 404 error from Visual Studio 2012

我花了一整天的時間試圖讓現有的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的\\區\\ 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優化,如果這些有影響

對不起,如果太長了

確保在應用程序啟動時調用AreaRegistration.RegisterAllAreas() 通常的地方是global.asax中的Application_Start

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM