5

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

8
  • 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 property Commented Dec 11, 2018 at 14:52
  • yes 2.2 compatibility and in process hosting Commented Dec 11, 2018 at 15:00
  • changing to 2.1 compatibility does solve the problem, but I want it to work with 2.2 compatibility Commented Dec 11, 2018 at 15:33
  • 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. Commented Dec 11, 2018 at 16:03
  • 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. Commented Dec 11, 2018 at 16:57

1 Answer 1

-1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I meant literally in the template, not as "defaults: new controller = .." The latter doesn't work if I try it. Defining it in the template does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.