asp.net-mvc - 如何禁用 ASP.NET MVC Core 2 中的防伪 token 检查

标签 asp.net-mvc asp.net-core-2.0 antiforgerytoken

我试图避免“AntiForgery”检查,因为从第 3 方服务器托管时它总是失败。我正在使用 ASP.NET Core 2.0 MVC 应用程序。

我在 ConfigureServices 函数中添加了此选项:

services
    .AddMvc()
    .AddRazorPagesOptions( options =>
    {
        options.Conventions.AuthorizeFolder("/Account/Manage");
        options.Conventions.AuthorizePage("/Account/Logout");
        options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
    } );

但我仍然遇到这个异常。

System.InvalidOperationException: The antiforgery token could not be decrypted.
System.Security.Cryptography.CryptographicException: The key {6fb328e7-4808-4b5d-b7dc-870d126e5ca4} was not found in the key ring.

我错过了什么吗?

最佳答案

IgnoreAntiforgeryToken 属性(订单必须 > 1000)添加到 razor 页面模型:

例如:

namespace CWACpch.Pages
{
    [IgnoreAntiforgeryToken(Order = 2000)]
    public class CreateOrderModel : PageModel
    {

关于asp.net-mvc - 如何禁用 ASP.NET MVC Core 2 中的防伪 token 检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50442256/

相关文章:

asp.net-mvc - asp.net mvc HTML5 日期输入类型

c# - Asp.Net Core 2.0 30 秒后注销

c# - "The {0} field is required"消息本地化

asp.net-mvc - AntiForgeryToken 在 ASP.Net MVC 4 RC 中已弃用

asp.net-mvc - ASP.NET MVC AntiForgeryToken 在 GET 上抛出异常?

asp.net-mvc - 防伪token功能安全吗?

asp.net-mvc - mvc [DataType(DataType.EmailAddress)无需验证

c# - Function 还是 async 可以细化吗?

c# - 哪个效率更高 : traditional routing or attribute routing?

log4net - 如何将log4net配置写入appsettings.json?