The Problem of Routing Mvc Areas in Asp.net

I want the default page on the site to be Login.cshtml. I get an exception:

Error: LogIn view or its wizard was not found or the viewer does not support the locations found. The following locations were searched:

I have 2 areas. The structure is shown below.

enter image description here

My routing file is shown below.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace Portal.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 = "LogIn", id = UrlParameter.Optional }, namespaces: new[] { "Portal.Web.Areas.Management" } ); } } } 

My global.asax.cs file is shown below:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Routing; namespace Portal.Web { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801 public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); } } } 

`Do you have any tips?

+4
source share
4 answers

I followed the instructions in this post. And the problem is solved. Visit Browse URL ASP.NET MVC URLs

Thanks to everyone.

-5
source

You forgot something about yourself.

Summary:

ManagementAreaRegistration.cs

 public class ManagementAreaRegistration : AreaRegistration { public override string AreaName { get { return "Management"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Management_default", "Management/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } 

RouteConfig.cs

 public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "Default" // Route name , "{controller}/{action}/{id}" // URL with parameters , new { area = "management", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults , new[] { "Portal.Web.Areas.Management.Controllers" } // Namespace of controllers in root area ); } 

You set Portal.Web.Areas.Management when it should be Portal.Web.Areas.Management.Controllers , also there is no default area = "management" : area = "management"

+7
source

It looks like you need to change the namespace on MapRoute with

 Portal.Web.Areas.Management 

To:

 Portal.Web.Areas.Management.Controllers 
+1
source

Empty the bin folder and rebuild. There is a chance that there is an old dll configured with old routing. At least it worked for me along one route.

-1
source

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


All Articles