I created MVC Application that have 3 different Area. (Admin, User, News) This is my RouteConfig.cs File in App_Start directory:
public class RouteConfig
{
From the code provided I can see 2 potential issues:
Try changing your code to:
Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "TestMvcApplication.Controllers" }
);
}
Admin area
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Just create a static class name it AreaConfig with a static method RegisterAreas() here code:
public static class AreaConfig
{
public static void RegisterAreas()
{
//
// Admin area . . .
var adminArea = new AdminAreaRegistration();
var adminAreaContext = new AreaRegistrationContext(adminArea.AreaName, RouteTable.Routes);
adminArea.RegisterArea(adminAreaContext);
//
// Default area . . .
var defaultArea = new DefaultAreaRegistration();
var defaultAreaContext = new AreaRegistrationContext(defaultArea.AreaName, RouteTable.Routes);
defaultArea.RegisterArea(defaultAreaContext);
}
}
then call it in a Global.asax.cs file like this:
protected void Application_Start()
{
. . .
AreaConfig.RegisterAreas();
. . .
}
Call AreaRegistration.RegisterAllAreas() somewhere in your RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
....
}
Tip: Use a tool like RouteDebugger 2.0 or Routing Debugger to investigate your routes
Get latest NuGet: Route Debugger for MVC or RouteDebugger for WepApi
Here's a tutorial on How to set up and use RouteDebugger with WebApi