【问题标题】:Error in "Authorization failed for the request at filter 'Abp.AspNetCore.Mvc.Antiforgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter"“过滤器'Abp.AspNetCore.Mvc.Antiforgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter 的请求授权失败”中的错误
【发布时间】:2020-12-21 06:57:19
【问题描述】:

我是 Asp.net Boilerplate 的新手,我跟随 Lee Richardson 在 YT 制作的教程。我还阅读了 asp.net 样板页面中关于 web 和动态 API 的文档。

现在,当我尝试在 POST、PUT 和删除请求中使用 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)
        {

        }
    }

【问题讨论】:

  • 我无法重现您的错误。您是否尝试过 (i) 清除浏览器缓存和 (ii) 浏览器隐身模式?
  • 是的,我尝试清除浏览器缓存并隐身使用 google chrome 和 IE edge
  • 我无法重现。你能发布堆栈跟踪吗?

标签: c# asp.net-core model-view-controller swagger aspnetboilerplate


【解决方案1】:

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

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

【讨论】:

  • 发布堆栈跟踪有助于快速识别。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
  • 2018-12-21
  • 2022-06-15
  • 1970-01-01
  • 2012-02-03
相关资源
最近更新 更多