Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Area routes not working in ASP.NET Core MVC when deploying on Azure

When running the app locally, all routing works fine. But when publishing to Azure, only the non-Area controllers work (such as "Home" and "Account"), the area-routes return 404.

Startup.cs has the following:

routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action=Index}/{id?}");

project.json has dependencies (amongst others):

"Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    }

and frameworks:

"netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }

and publishOptions:

"include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
like image 274
Martin Åhlin Avatar asked Aug 11 '16 09:08

Martin Åhlin


2 Answers

There's an issue with the globbing pattern that is being tracked via https://github.com/dotnet/cli/issues/3795. Listing individual areas in the publish/include section could be used as a workaround. For instance,

"include": [
  "wwwroot",
  "Views",
  "Areas/Area1/Views",
  "Areas/Area2/Views",
  "appsettings.json",
  "web.config"
]
like image 132
Pranav Avatar answered Oct 06 '22 20:10

Pranav


The problem was fixed for me by checking all ".cshtml" files have "Build Action: Content" set in the properties window. For some reason, my Index.cshtml was set to "Build Action: None".

like image 23
Tony Wall Avatar answered Oct 06 '22 22:10

Tony Wall