如何从ASP.NET Core 2.1 API获取401未经授权的详细信息

编程入门 行业动态 更新时间:2024-10-24 15:26:38
本文介绍了如何从ASP.NET Core 2.1 API获取401未经授权的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用ASP.NET API(内置于Core 2.1中),当尝试从测试应用程序中调用它时,我得到了401 Unauthorized.但是,据我所知,访问令牌很好.有没有办法从ASP.NET Core 2.1中的身份验证处理程序中获取有关无效内容的更多详细信息?如果我能对令牌有什么问题有所了解,我应该能够找到一种解决方案来纠正它,但是现在我正在黑暗中绊倒,只是尝试各种事情(最有可能的是,我只是在做它.更糟).

I am working on an ASP.NET API (built in Core 2.1) and when trying to call it from a test application, I am getting a 401 Unauthorized. However, near as I can tell, the Access Token is fine. Is there a way to get more details about what is invalid from the Authentication handler in ASP.NET Core 2.1? If I can get some idea of what is wrong with the token, I should be able to find a solution to correct it, but right now I am stumbling around in the dark and just trying various things (most likely, I am just making it worse).

推荐答案

检查日志或服务器的事件查看器.

Check logs or the events viewer of your server.

对于您的错误,请检查是否正在调用app.UseAuthentication()作为Configure()中的第一个方法,甚至在UseMVC()之前.

For your error, check if you're calling app.UseAuthentication() as the first method in Configure(), even before UseMVC().

如果您提到了错误的子代码,这将有所帮助:

It will helps if you've mentioned subcode of the error :

401.1: Access is denied due to invalid credentials. 401.2: Access is denied due to server configuration favoring an alternate authentication method. 401.3: Access is denied due to an ACL set on the requested resource. 401.4: Authorization failed by a filter installed on the Web server. 401.5: Authorization failed by an ISAPI/CGI application. 401.7: Access denied by URL authorization policy on the Web server.

更多推荐

如何从ASP.NET Core 2.1 API获取401未经授权的详细信息

本文发布于:2023-05-26 10:43:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/355040.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:详细信息   未经授权   Core   NET   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!