1

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

3
  • Have you called AreaRegistration.RegisterAllAreas(); in global.asax? Commented Mar 21, 2014 at 16:36
  • It has no global.asax file and works like that at the office Commented Mar 21, 2014 at 16:40
  • My mistake. The solution I was working on excluded the start-up project which has the global.asax. Now working. Marked your response as an answer. Commented Mar 28, 2014 at 3:39

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Richard, thanks. It turned out that I had opened a solution that did not include one of the projects that was the start-up project. It has the global.asax and Application_Start. Will mark yours as an answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.