.Net 2 Flashcards
Do you need to register DeveloperExceptionPageMiddleware in .net 6?
No. It’s registered automatically when ASPNETCORE_ENVIRONMENT = Development
How to add a custom filter for
Just register singleton realization of IDeveloperPageExceptionFilter.
What app.UseHttpsRedirection() does?
It registers HttpsRedirectionMiddleware, that redirects all non-HTTPS requests to HTTPS
What builder.Services.AddRazorPages() does?
Performs the next call
services
.AddMvcCore()
.AddAuthorization()
.AddDataAnnotations()
.AddRazorPages()
.AddCacheTagHelper();
AddMvcCore() creates MvcCoreBuilder
So next call of AddRazorPages is extension method on IMvcCoreBuilder.
So the call registers everything razor pages need in order to work with MVC.
IMvcCoreBuilder.AddRazorPages() adds AddRazorViewEngine with all required services and options, e.g. RazorViewEngineOptions, RazorPagesOptions, caches
What app.MapRazorPages() does?
It adds data source for razor pages (PageActionEndpointDataSource) to IEndpointRouteBuilder.DataSources.
IEndpointRouteBuilder.DataSources is used in EndpointRoutingMiddleware (UseRouting) for matching requests to endpoints.
As a result, all razor pages in ApplicationParts will have an endpoint now. Your project is default ApplicationPart, if you have some external project you have to register it as ApplicationPart. For example Microsoft.AspNetCore.Identity.UI do it for default identity pages like login, register, etc.
ApplicationPart of a project is called AssemblyPart