简体   繁体   English

asp.net core - 在哪里调用 MapRazorPages?

[英]asp.net core - where to call MapRazorPages?

In ASP.NET Core 3.x, we add endpoints for Razor Pages with在 ASP.NET Core 3.x 中,我们为 Razor 页面添加了端点

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

In the ASP.NET Core 6 Web App template (minimal hosting model), this has been changed to:在 ASP.NET Core 6 Web App 模板(最小托管模型)中,这已更改为:

app.MapRazorPages();

From MS docs page :从 MS 文档页面

Apps typically don't need to call UseRouting or UseEndpoints.应用程序通常不需要调用 UseRouting 或 UseEndpoints。 WebApplicationBuilder configures a middleware pipeline that wraps middleware added in Program.cs with UseRouting and UseEndpoints. WebApplicationBuilder 配置一个中间件管道,该管道使用 UseRouting 和 UseEndpoints 包装 Program.cs 中添加的中间件。 For more information, see Routing in ASP.NET Core.有关详细信息,请参阅 ASP.NET Core 中的路由。

My questions are:我的问题是:

  1. Do the 2 method calls above have the same effect?上面的2个方法调用有同样的效果吗?
  2. Am I correct to assume that the second way (ie app.MapRazorPages() ) is possible due to the middleware pipeline configuration by WebApplicationBuilder ?由于WebApplicationBuilder的中间件管道配置,我假设第二种方式(即app.MapRazorPages() )是正确的吗? (see snippet from MS docs above). (参见上面 MS 文档的片段)。

Thank you in advance.先感谢您。

Short answer: Yes.简短的回答:是的。 They are using the same method.他们使用相同的方法。

Details you could see below explain:您可以在下面看到的详细信息解释:

endpoint.MapRazorPages():端点.MapRazorPages():

在此处输入图像描述

app.MapRazorPages();: app.MapRazorPages();:

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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