5
votes

After updating my app from asp.net core 2.1 to 2.2 it seems that default route action is not working for controllers that live in a separate class library.

For example I have a default route like this:

routes.MapRoute(
            name: "default",
            template: "{controller}/{action}"
            ,defaults: new { controller = "Home", action = "index" }
            );

and in my class library I have a controller SiteAdminController which has an Index action method.

When I visit the url /siteadmin I get the HomeController index and not the index action of the SiteAdminController

if I use /siteadmin/index then it works

How can I make it work without requiring the index action to be explicitly in the url? It worked fine in 2.1

1
Are you using the 2.2 compatibility level? .AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)? or the old 2_1 compatibility? (it determines if endpoint routing is used or the mvc router middleware). Can also be disabled separately via MvcOption's EnableEndpointRouting propertyTseng
yes 2.2 compatibility and in process hostingJoe Audette
changing to 2.1 compatibility does solve the problem, but I want it to work with 2.2 compatibilityJoe Audette
having trouble trying to replicate this issue in a new solution, can't figure out what is different in my main solution that could be causing this.Joe Audette
strangely I can't seem to reproduce this in other solutions than the main dev solution for cloudscribe core. If anyone wants to try to help figure it out the repo is here:github.com/cloudscribe/cloudscribe Note that even new projects created with our project template and using our nugets, when upgraded to netcoreapp2.2 work just fine. At the moment I'm stumped why this problem happens.Joe Audette

1 Answers

-1
votes

Have you tried setting the defaults in the template?

app.UseMvc(routes =>
        {
            routes.MapRoute(
              name: "default", 
              template: "{controller=Home}/{action=Index}");
        }
);

This worked for me in Core 2.2