b.UseM-6ren">
gpt4 book ai didi

.net - ASP.NET Core 3.0 端点路由和自定义中间件

转载 作者:行者123 更新时间:2023-12-04 21:29:07 28 4
gpt4 key购买 nike

.NET 3.0 中的这段代码用端点路由替换了什么?

app.UseRouter(a => a.MapMiddlewareGet(
"middleware1",
b => b.UseMiddleware<Middleware1>()));


还是应该像这样留下:
app.UseRouter(a => a.MapMiddlewareGet(
"middleware1",
b => b.UseMiddleware<Middleware1>()));
app.UseEndpoints(a => a.MapControllers());

最佳答案

我认为以下代码可以帮助您。我已经测试过了,它正在工作。

app.UseEndpoints(endpoints =>
{
var newAppbuilder = endpoints.CreateApplicationBuilder();
newAppbuilder.UseMiddleware<Middleware1>();

endpoints.MapGet("middleware1", newAppbuilder.Build());
});

关于.net - ASP.NET Core 3.0 端点路由和自定义中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58069969/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com