如何解决“在过滤器‘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 登录。
现在,我可以运行它而不会再次看到这些错误,并且能够将数据插入到表中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。