简体   繁体   中英

asp.net core - where to call MapRazorPages?

In ASP.NET Core 3.x, we add endpoints for Razor Pages with

app.UseEndpoints(endpoint =>
{
    endpoint.MapRazorPages();
});

In the ASP.NET Core 6 Web App template (minimal hosting model), this has been changed to:

app.MapRazorPages();

From MS docs page :

Apps typically don't need to call UseRouting or UseEndpoints. WebApplicationBuilder configures a middleware pipeline that wraps middleware added in Program.cs with UseRouting and UseEndpoints. For more information, see Routing in ASP.NET Core.

My questions are:

  1. Do the 2 method calls above have the same effect?
  2. Am I correct to assume that the second way (ie app.MapRazorPages() ) is possible due to the middleware pipeline configuration by WebApplicationBuilder ? (see snippet from MS docs above).

Thank you in advance.

Short answer: Yes. They are using the same method.

Details you could see below explain:

endpoint.MapRazorPages():

在此处输入图像描述

app.MapRazorPages();:

});

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