Getting error 404 not found with ASP.NET MVC Area routing Getting error 404 not found with ASP.NET MVC Area routing asp.net asp.net

Getting error 404 not found with ASP.NET MVC Area routing


It is important tha you add the correct namespace to your controller

  namespace YourDefaultNamespace.Areas.Evernote.Controllers  {    public class EvernoteAuthController : Controller    {         ...        ...    }  }

So the routing can find your controller.Now you have to register the area in the Global.asax.cs with the method

AreaRegistration.RegisterAllAreas();


Be careful with AreaRegistration.RegisterAllAreas(); inside Application_Start method.

If you put AreaRegistration.RegisterAllAreas() to be last inside Application_Start that will not work.

Put AreaRegistration.RegisterAllAreas() to be first and routing will be successfully executed..

Example:

 protected void Application_Start(object sender, EventArgs e) {        AreaRegistration.RegisterAllAreas();  //<--- Here work        FilterConfig.Configure(GlobalFilters.Filters);        RouteConfig.Configure(RouteTable.Routes);        AreaRegistration.RegisterAllAreas();  //<--- Here not work }


Like you found in my post at http://legacy.piranhacms.org/the-magic-of-mvc-routing-with-multiple-areas you probably figured out the all controllers are mapped to the default route (i.e the one you added manually in your route config). If it has been added to the default route, then it will search the location for the default route for its views, i.e ~/Views/...

So the error really seems to be that the Area isn't configured properly. Make sure that you have the following line in your Global.asax.xs:

AreaRegistration.RegisterAllAreas();

This is the line that actually sets up the areas and makes sure that when a controller within a area is hit, the view directory of that area is searched, in your case ~/Areas/Evernote/Views. The thing covered in my blog post was how to eliminate that controllers from your Evernote area are being mapped in the default route.

Hope this help!

Regards

HÃ¥kan