路由是通过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
本文链接:https://blog.nnwk.net/article/59
有问题请留言。版权所有,转载请在显眼位置处保留文章出处,并留下原文连接
Leave your question and I'll get back to you as soon as I see it. All rights reserved. Please keep the source and links
友情链接:
子卿全栈
全部评论