路由是通过UseRouting和UseEndpoints两个中间件配合在一起来完成注册的:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// 添加Routing相关服务
// 注意,其已在 ConfigureWebDefaults 中添加,无需手动添加,此处仅为演示
services.AddRouting();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
}
}
UseRouting与UseEndpoints必须同时使用,而且必须先调用UseRouting,再调用UseEndpoints
更深度请参考原文,连接 https://www.cnblogs.com/xiaoxiaotank/p/15468491.html
友情链接:
全部评论