Home > Enterprise >  MapAreaControllerRoute for Identity area in .NET Core 6 does not work
MapAreaControllerRoute for Identity area in .NET Core 6 does not work

Time:11-04

This customization takes no effect:

app.MapAreaControllerRoute(
     name: "Identity",
     areaName: "Identity",
     pattern: "Identity/xx/{controller=Home}/{action=Index}/{id?}");

MapAreaControllerRoute has been added right before the default MapControllerRoute in Program.cs main function

PS: in Identity area there is no controller so you can't add an area attribute there

CodePudding user response:

To configure localization route for the Asp.net core Identity Scaffold Razor pages, we can use the AddAreaFolderRouteModelConvention method to add Convention, like this:

services.AddMvc()
    .AddRazorPagesOptions(options =>
    {
        options.Conventions.AddAreaFolderRouteModelConvention("Identity", "/Account/", model =>
         {
             model.Selectors.ForEach(x =>
             {
                 if (x.AttributeRouteModel.Template.StartsWith("Identity"))
                 {
                     x.AttributeRouteModel = new AttributeRouteModel()
                     {
                         Order = -1,
                         Template = AttributeRouteModel.CombineTemplates(("{culture=en-US}"),
                             x.AttributeRouteModel.Template)
                     };
                 }
             }); 
         });
    });

Refer to this thread: Routed localization in identity pages in ASP.NET MVC Core.

  • Related