locked
Net Core 5.0 MVC routing some confusion RRS feed

  • Question

  • User-1250245744 posted

    The project has two requirements

    First: The project belongs to the management background, and the background path needs to be changed, which requires that Areas need to have a custom name.

    Second: when the project needs to access the URL, the default increment.HTML suffix name

    I define this in startup.cs

          app.UseEndpoints(endpoints =>
                {
                    string adminpath = AppSettingsHelper.Configuration["SiteSetting:AdminPath"];
                    endpoints.MapControllerRoute(name: "Areas", pattern: adminpath+"/{controller}/{action}.html");
                    //endpoints.MapControllerRoute(name: "Areas", pattern: adminpath + "/{controller}/{action}");
                    endpoints.MapControllerRoute( name: "default", pattern:"{controller=Home}/{action=Index}/{id?}");
                });

    • The annotated one

    endpoints.MapControllerRoute(name: "Areas", pattern: adminpath + "/{controller}/{action}")

    At present, there is no problem with the visit and everything is normal

    But this one, it's not

    endpoints.MapControllerRoute(name: "Areas", pattern: adminpath+"/{controller}/{action}.html");

    Under the same controller, different Actions create conflicts

    Urgently needed solutions, or my solution itself is wrong, there is no better solution, thank you very much



    Monday, November 16, 2020 1:22 AM

All replies