locked
Migrating from VS 2013 to VS 2017 MVC routing issues RRS feed

  • Question

  • User-1292195402 posted

    I currently have 2 MVC websites, both built originally as ASP.NET forms applications in Visual Studio 2013 with .NET framework version 4.5. They were later migrated to an MVC platform in Visual Studio 2013, without changing the framework version. We are currently trying to upgrade both projects to the latest version of .NET (4.6) and switch to Visual Studio 2017 for development, testing, and deployment of both applications.

    The conversion of the projects to VS2017 encountered one issue which seems rooted in a fundamental change to the ASP.NET MVC framework that was implemented with the release of VS2017. The problem manifested itself in one of our applications which uses 2 separate MVC Areas in its routing scheme. We do not, for the most part, use the auto-generated folders for Controllers, Models, and Views that are created with a new MVC project template. Rather, there is a folder for 'Areas' with 2 subfolders. These are a standard 'Home' area/folder, with its main folder and subfolders for Controllers, Models, and Views which are accessed by the routing engine.

    We also have an 'Applications' area/folder (applications refers to applying to be part of our organization, not web applications). This has the same sub-structure as the 'Home' folder with Controllers, Models, and Views separated into sub-folders. In the current working version of our code, either area can be accessed using a parameter indicating the correct area (e.g. '….{new Area="Applications"}' or the method, controller, and area (e.g. href="@Url.Action("Index", "Teacher", new { area = "Applications" })").

    While the 'Home' area runs as expected in the new VS2017 environment, it seems that the new routing engine is unable to recognize and locate the controllers and views in the 'Applications' area. It returns a 404 error for all methods / views in the 'Applications' area. Any pointers as to what changed need to be done to make the original project compatible with VS-2017, as I am getting a 404 error when trying to access views from the second 'area' in the project when running it.

    Thursday, June 22, 2017 3:33 PM

All replies

  • User1068175894 posted

    in your RegisterRoutes method call register areas:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        AreaRegistration.RegisterAllAreas();
        ....
    }

    more details on:

    https://msdn.microsoft.com/en-us/library/ee671793(v=vs.98).aspx 

    Thursday, June 22, 2017 10:20 PM
  • User1967761114 posted

    Hi  HB_123,

    According to your description, it seems like there had same controller name in different areas.

    I suggest you could add the namespace when register the area, see the following code:

    public class ApplicationAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "Application";
            }
        }
    
        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Application_default",
                "Application/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                //namespace
                new string[] { "WebSite.Areas.Application.Controllers" }
            );
        }
    }

     

    If you have any other questions, please feel free to contact me any time.

    Best Regards

    Even

    Friday, June 23, 2017 9:01 AM