Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
A new overload of app.Use
has been introduced. If you call app.Use
but never call the next
middleware, you'll now get compiler error CS0121:
The call is ambiguous between the following methods or properties: 'UseExtensions.Use(IApplicationBuilder, Func<HttpContext, Func, Task>)' and 'UseExtensions.Use(IApplicationBuilder, Func<HttpContext, RequestDelegate, Task>)'
To resolve the error, use app.Run
instead of app.Use
.
For discussion, see GitHub issue dotnet/aspnetcore#32020.
ASP.NET Core 6.0
app.Use(async (context, next) =>
{
await next();
});
or
app.Use(async (context, next) =>
{
await SomeAsyncWork();
// next not called...
});
You can now pass context
to the next
delegate:
app.Use(async (context, next) =>
{
await next(context);
});
Use app.Run
when your middleware never calls next
:
app.Run(async (context) =>
{
await SomeAsyncWork();
// next never called
});
The previous Use
method allocates two objects per request. The new overload avoids these allocations with a small change to how you invoke the next
middleware.
If you get a compile error, it means you are calling app.Use
without using the next
delegate. Switch to app.Run
to fix the error.
None.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Customize ASP.NET Core behavior with middleware - Training
Understand and implement middleware in an ASP.NET Core app. Use included middleware like HTTP logging and authentication. Create custom middleware to handle requests and responses.