Attribute on a method a route handler calls (ASP0005)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key dotnet.api.route-handler-attribute-on-called-method · Severity warning · Category api
ASP.NET Core analyzer ASP0005. Flags an attribute such as [Authorize] placed on a method that a route handler lambda merely calls - the attribute only works on the handler itself, so it is silently ignored.
Incorrect
Section titled “Incorrect”app.MapGet("/admin", () => Admin());
[Authorize(Roles = "Admin")]static string Admin() => "ok";Correct
Section titled “Correct”app.MapGet("/admin", [Authorize(Roles = "Admin")] () => Admin());
static string Admin() => "ok";