Skip to content

Commit 25e068c

Browse files
committed
Register global antiforgery token validation
Change will not affect behavior of template, as per Microsoft documentation : "In ASP.NET Core 2.0 or later, the FormTagHelper injects antiforgery tokens into HTML form elements. The following markup in a Razor file automatically generates antiforgery tokens: <form method="post"> ... </form>" (REF: https://docs.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-3.1)
1 parent bfa919e commit 25e068c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ASP.NET Core/Web/AspNetCoreTemplate.Web/Startup.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Microsoft.AspNetCore.Builder;
1717
using Microsoft.AspNetCore.Hosting;
1818
using Microsoft.AspNetCore.Http;
19+
using Microsoft.AspNetCore.Mvc;
1920
using Microsoft.EntityFrameworkCore;
2021
using Microsoft.Extensions.Configuration;
2122
using Microsoft.Extensions.DependencyInjection;
@@ -46,7 +47,11 @@ public void ConfigureServices(IServiceCollection services)
4647
options.MinimumSameSitePolicy = SameSiteMode.None;
4748
});
4849

49-
services.AddControllersWithViews();
50+
services.AddControllersWithViews(options =>
51+
{
52+
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
53+
});
54+
5055
services.AddRazorPages();
5156

5257
services.AddSingleton(this.configuration);

0 commit comments

Comments
 (0)