How to add AllowAnonymous when using MinimalAPIs?

Viewed 26

How to allow anonymous access to an endpoint when using MinimalAPIs?

Assume I have the code below in the Program.cs file of a web app, using the Minimal API syntax:

app.MapGet("/hello", () => "world");

When using non-minimal syntax, we could allow anonymous access to an endpoint by decorating a controller with an [AllowAnonymous] attribute.

How would I perform the same when using the minimal syntax?

2 Answers
Related