用端点路由将.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());
});