在一个操作上覆盖全局 AutoValidateAntiforgeryTokenAttribute
Override global AutoValidateAntiforgeryTokenAttribute on one Action
我正在使用 Startup.cs 中配置的全局 AutoValidateAntiforgeryTokenAttribute,但我需要为两个操作禁用它,有没有办法覆盖这个或者是全部还是 none 当完成这个方法?当整个应用程序中只有两个不需要它的动作时,我宁愿不将属性添加到每个动作...
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => {
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
}
找了一段时间的文档,找到了答案... action方法可以用IgnoreAntiforgeryToken Attribute修饰。
[HttpPost]
[AllowAnonymous]
[IgnoreAntiforgeryToken]
public async Task<IActionResult> MyAction()
{ ... }
我正在使用 Startup.cs 中配置的全局 AutoValidateAntiforgeryTokenAttribute,但我需要为两个操作禁用它,有没有办法覆盖这个或者是全部还是 none 当完成这个方法?当整个应用程序中只有两个不需要它的动作时,我宁愿不将属性添加到每个动作...
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => {
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
}
找了一段时间的文档,找到了答案... action方法可以用IgnoreAntiforgeryToken Attribute修饰。
[HttpPost]
[AllowAnonymous]
[IgnoreAntiforgeryToken]
public async Task<IActionResult> MyAction()
{ ... }