MVC5 scope not working

I have two areas in my MVC 5 application that are not working properly.

When I use the following link http://localhost:45970/Admin/Admin, the application loads the corresponding index.cshtml whicxh located in /Areas/Admin/Views/Admin/Index.cshtml, but when I try to download http://localhost:45970/Admin, it tries to load the Index.cshtml file from /Views/Admin/Index.cshtml.

All search results say I'm doing the right thing. I even downloaded a sample API project to look at the help area in it to make sure that I am doing everything right.

Here is my RouteConfig.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace BlocqueStore_Web
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                namespaces: new[] { "BlocqueStore_Web.Controllers" }
            );
        }
    }
}

Here is the Application_Start () section of my Global.asax.cs file

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

And finally, the AdminAreaRegistration.cs file

using System.Web.Mvc;

namespace BlocqueStore_Web.Areas.Admin
{
    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 { action = "Index", id = UrlParameter.Optional },
                namespaces: new[] { "BlocqueStore_Web.Areas.Admin.Controllers" }
            );
        }
    }
}

So what am I missing?

+4
1

Admin. Admin Index defaults context.MapRoute

public override void RegisterArea(AreaRegistrationContext context) 
{
    context.MapRoute(
        "Admin_default",
        "Admin/{controller}/{action}/{id}",
        defaults: new { action = "Index", controller = "Admin", id = UrlParameter.Optional },
        namespaces: new[] { "BlocqueStore_Web.Areas.Admin.Controllers" }
    );
}
+3

Source: https://habr.com/ru/post/1651474/


All Articles