.netcore 3.1 反跨站请求伪造 电脑版发表于:2020/10/12 16:17 ![.netcore](https://img.tnblog.net/arcimg/hb/c857299a86d84ee7b26d181a31e58234.jpg ".netcore") >#.netcore 3.1 反跨站请求伪造 [TOC] <br/> >###CSRF验证 ```csharp services.AddAntiforgery(options => { options.HeaderName = "X-CSRF-TOKEN"; }); ``` >###开启全局AntiforgeryToken验证(包括post页面都是需要去携带的) ```csharp services.AddMvc(options => options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute())); ``` >###针对单个接口进行防御 ```csharp [ValidateAntiForgeryToken] ``` >###只针对控制器的Post进行防御 ```csharp [AutoValidateAntiforgeryToken] ```