“在过滤器‘Abp.AspNetCore.Mvc.Antiforgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter’处请求的授权失败”中的错误

问题描述

我是 Asp.net Boilerplate 的新手,我会继续学习 Lee Richardson 在 YT 上制作的教程。我还阅读了 asp.net 样板页面中有关 Web 和动态 API 的文档。

现在,当我尝试在 POST、PUT 和 Delete 请求中使用 Swagger 和 Postman 时,我遇到了这个错误

Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: information: Authorization Failed for the request at filter 'Abp.AspNetCore.Mvc.Antiforgery.AbpAutovalidateAntiforgeryTokenAuthorizationFilter'.
Microsoft.AspNetCore.Mvc.StatusCodeResult: information: Executing HttpStatusCodeResult,setting HTTP status code 400

但是我在 Get 方法中没有遇到任何错误。我是否错过了配置或任何文件中的某些内容?请帮忙。感谢您的帮助,并提前感谢您。

这是我的 DTO 和服务类

[AutoMap(typeof(SinkingGroup))]
    public class SinkingGroupDto : EntityDto<int>,IFullAudited,ISoftDelete
    {
        [required]
        public string GroupName { get; set; }
        public int MembersCount { get; set; }
        public long? CreatorUserId { get ; set ; }
        public DateTime CreationTime { get ; set ; }
        public long? LastModifierUserId { get ; set ; }
        public DateTime? LastModificationTime { get ; set ; }
        public long? DeleterUserId { get ; set ; }
        public DateTime? DeletionTime { get ; set ; }
        public bool IsDeleted { get ; set ; }
    }
[AbpAuthorize]
    public class SinkingGroupAppService : AsyncCrudAppService<SinkingGroup,SinkingGroupDto> 
    {
        public SinkingGroupAppService(IRepository<SinkingGroup,int> repository)
            : base(repository)
        {

        }
    }

解决方法

感谢您的帮助@aaron。我想出了我收到此错误的原因。 这是因为我运行的是 web.mvc 项目而不是 web.host 项目。如果使用 web.host,这将在启动项目时重定向到 swagger ui,然后单击授权以使用 swagger 登录。

现在,我可以运行它而不会再次看到这些错误,并且能够将数据插入到表中。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...