0

I have an ASP.NET Core 3.1 MVC app, I have in my startup.cs file the predefined call:

app.UseEndpoints(endpoints =>
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

in the Configure() method.

This is to route every undefined url to the Home/Index action.

I want to add another endpoint mapping that allows me to route any request that corresponds to the pattern:

{controller}/{action}

to the specified controller/action method.

I know this was easy in ASP.NET MVC where you just added the related url in the routing file :

Route.add (
     name  : "routename",
     url : "{controller}/[action}/{id?}"
)

Is there a similar, easy way to do it with ASP.NET Core 3.1?

3
  • It’s not clear enough what your problem is if you are using only generic route already defined in the startup.cs like you described? Commented May 23, 2024 at 8:38
  • Exactly, I just have the predefined route : name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); that comes with the template : I would like to add another one that routes depending on the content of the post , like in : "{controller}/{action}/{id}" Commented May 23, 2024 at 9:12
  • You can add multiple route configuration i.e. multiple endpoints.MapControllerRoute inside app.UseEndpoints. Check this documentation, it will be helpful learn.microsoft.com/en-us/aspnet/core/mvc/controllers/…. Commented May 23, 2024 at 9:54

0

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.