简体   繁体   中英

How to reproduce ASP.NET Core 6 conventions (post configure route)

Documentation contains something unclear and unbind to finally result description about conventions https://docs.microsoft.com/en-us/aspnet/core/razor-pages/razor-pages-conventions?view=aspnetcore-6.0#page-route-action-conventions

I don't understand how to use this documentation to reproduce a needed result.

Currently I have these route rules:

Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/2 GET https://localhost:7168/?area=Identity&page=%2FAccount%2FLogin - -
Endpoint: FrontEnd.Controllers.HomeController.Index (FrontEndCode) RoutePattern: {controller=Home}/{action=Index}/{id?}  
Endpoint Metadata 0: Microsoft.AspNetCore.Mvc.ControllerAttribute
Endpoint Metadata 1: Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor
Endpoint Metadata 2: Microsoft.AspNetCore.Routing.DataTokensMetadata
Endpoint Metadata 3: Microsoft.AspNetCore.Routing.RouteNameMetadata
Endpoint Metadata 4: Microsoft.AspNetCore.Mvc.Filters.ControllerActionFilter
Endpoint Metadata 5: Microsoft.AspNetCore.Mvc.ViewFeatures.SaveTempDataAttribute
Endpoint Metadata 6: Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter
Endpoint Metadata 7: Microsoft.AspNetCore.Routing.SuppressLinkGenerationMetadata

I want to get these rules:

Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/2 GET https://localhost:7167/Identity/Account/Login - -
Endpoint: /Account/Login
RoutePattern: Identity/Account/Login
Endpoint Metadata 0: Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute
Endpoint Metadata 1: Microsoft.AspNetCore.Identity.UI.IdentityDefaultUIAttribute
Endpoint Metadata 2: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageModelAttribute
Endpoint Metadata 3:  Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute
Endpoint Metadata 4: System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute
Endpoint Metadata 5: Microsoft.AspNetCore.Mvc.ApplicationModels.PageRouteMetadata
Endpoint Metadata 6: Microsoft.AspNetCore.Mvc.RazorPages.CompiledPageActionDescriptor
Endpoint Metadata 7: Microsoft.AspNetCore.Routing.RouteNameMetadata
Endpoint Metadata 8: Microsoft.AspNetCore.Mvc.Filters.PageHandlerPageFilter
Endpoint Metadata 9: Microsoft.AspNetCore.Mvc.ViewFeatures.SaveTempDataAttribute
Endpoint Metadata 10: Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter
Endpoint Metadata 11: Microsoft.AspNetCore.Mvc.Filters.PageSaveTempDataPropertyFilterFactory
Endpoint Metadata 12: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.HandleOptionsRequestsPageFilter
Endpoint Metadata 13: Microsoft.AspNetCore.Mvc.AutoValidateAntiforgeryTokenAttribute

Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executing endpoint '/Account/Login'

After analyzing options I have understand that this rules adding by two PostConfigure convention rules

PostConfigure 约定

How to write action for conventions to receive 6 additional needed attributes? How to write PostConfigure actions at all?

I have download MS example about conventions https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/razor-pages/razor-pages-conventions/samples/6.x/SampleApp and I can not see ANY answer to real practical questions about conventions actions. Moreover MS made conventions class private and nobody can print or analyzing action, action write as lambda expression and also unclear. I have changed code of workable project and my project unexpectedly lost 6 route attribute and this two actions in PostConfigure convention rules. I don't understand how to reproduce this two actions, how to add 6 route attributes.

I found PostConfigure convention in MS source code.

IdentityDefaultUIConfigureOptions

So, if you want to add 13 attributes and PostConfigure convention you need to something like that

 Builder.Services.
 AddIdentity(Of ApplicationUser, ApplcationRole).
 AddDefaultUI().
 AddDefaultTokenProviders().
 AddUserStore(Of CustomUserStore).
 AddRoleStore(Of CustomRoleStore)() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM