Skip to content

Commit 31a7548

Browse files
Update global application example of AutoValidateAntiForgeryTokenAttribute (dotnet#17045)
* Update AutoValidateAntiForgeryToken example * Update anti-request-forgery.md Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
1 parent 90118dc commit 31a7548

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

aspnetcore/security/anti-request-forgery.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,22 @@ public class ManageController : Controller
328328

329329
Global example:
330330

331+
::: moniker range="< aspnetcore-3.0"
332+
333+
services.AddMvc(options =>
334+
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()));
335+
336+
::: moniker-end
337+
338+
::: moniker range=">= aspnetcore-3.0"
339+
331340
```csharp
332-
services.AddMvc(options =>
341+
services.AddControllersWithViews(options =>
333342
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()));
334343
```
335344

345+
::: moniker-end
346+
336347
### Override global or controller antiforgery attributes
337348

338349
The [IgnoreAntiforgeryToken](/dotnet/api/microsoft.aspnetcore.mvc.ignoreantiforgerytokenattribute) filter is used to eliminate the need for an antiforgery token for a given action (or controller). When applied, this filter overrides `ValidateAntiForgeryToken` and `AutoValidateAntiforgeryToken` filters specified at a higher level (globally or on a controller).

0 commit comments

Comments
 (0)