Question

I have spent the whole day trying to get an existing MVC application to work.

I have a the following situation:

1) I started working on an existing ASP.Net MVC Application with a custom area

2) It is working well at the office

3) I am at home and I VPN'ed and got the latest code from TFS

4) It is building successfully but if I try to run it from within Visual Studio 2012, it cannot see the registered areas

HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following

URL and make sure that it is spelled correctly.

A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

5) I created an ordinary MVC website (NO AreaRegistrations) and ran it in Visual Studio 2012, it gives no errors

6) I have tried RouteDebugger and I keep getting the following error:

Sequence contains no elements

I have also gotten stuck trying to resolve that. If there is another way to actually step into it to see where it is failing, it would help.

In the actual Area folder: MyProject\Areas\MyCustomArea I have

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);
            }
        }
    }

And 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" });
        }
    }
}

My App_Start Folder has NO Route.config.cs file

I have a MyProject\packages.config with the following:

<?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>

I use System.Web.Optimization

My Web.config file has the following:

  <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>

Is there anything I may need to do to get it to work, bearing in mind that it works at work and I use RazorGenerator as well as Web Optimization, if those have an impact

Sorry if it was too long

Was it helpful?

Solution

Ensure that AreaRegistration.RegisterAllAreas() is called in your application startup. The usual place is in Application_Start in global.asax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top