dotnet / dotnet/AspNetCore.Docs.Samples
Antiforgery integration for minimal APIs
- Vorherrschende Sprache
- C#
- Sterne
- 225
- Forks
- 170
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne mit den Einstiegspunkten in fundamentals/minimal-apis/samples/MyAntiForgery/Program.cs, auf die verwiesen wird, insbesondere mit der HTML-Generierung um die Zeilen 16–17 und 57. Vergleiche, wie das action-Argument und AntiforgeryTokenSet in das Formular-Markup übergeben werden; als erledigt gilt die Aufgabe, wenn das Beispiel einen klaren, wartbaren Ansatz ohne eine ungeklärte Null-Token-Frage oder unnötig dupliziertes HTML hat.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp
- Bereich
- backend-api-design, documentation, security
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100