dotnet / dotnet/AspNetCore.Docs.Samples

Antiforgery integration for minimal APIs

Open
#173 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
225
Forks
170
PR merge metrics
No merged PRs in 30d

Description

See [Antiforgery integration for minimal APIs](https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-8-preview-7/#antiforgery-integration-for-minimal-apis)

and [this sample](https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/fundamentals/minimal-apis/samples/MyAntiForgery/Program.cs#L16-L17)

In [this code](https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/fundamentals/minimal-apis/samples/MyAntiForgery/Program.cs#L57) I pass in the action so

```
app.MapGet("/DisableAntiforgery", () =>
{
return Results.Content(MyHtml.html("/todo"), "text/html");
});

app.MapGet("/post2", () =>
{
return Results.Content(MyHtml.html("/todo2"), "text/html");
});
```

Can use the same HTML when they pass in the action arg.

Is there a clean way to do this to pass in an arg for
```

```

Maybe that makes things too messy. Perhaps I should duplicate most of the HTML and not get the HTML from a method while passing the action.

```
public static string html2(string action, AntiforgeryTokenSet token) => $"""









""";
```
Works, but I'm not sure it's an improvement. There's no way to pass in a null token.

@sammychinedu2ky @david-acker

cc @guardrex

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.