英文:
Get BasicAuth credentials from HttpContext?
问题
你可以从 Microsoft.AspNetCore.Http.HttpContext
对象中以某种方式获取已使用的 BasicAuth 凭据吗?
英文:
Can I get the used BasicAuth credentials from a Microsoft.AspNetCore.Http.HttpContext
object somehow?
答案1
得分: 3
从HttpContext.Request.Headers
中读取Authorization
头部(ctx.Request.Headers.Authorization
或ctx.Request.Headers[HeaderNames.Authorization]
,前者是后者的别名)。它应该包含类似于Basic .....
的内容,其中第二部分存储了使用Base64编码的用户ID/密码对作为凭据。
英文:
Read the Authorization
header from HttpContext.Request.Headers
(ctx.Request.Headers.Authorization
or ctx.Request.Headers[HeaderNames.Authorization]
the former being alias for the latter). It should contain something like Basic .....
where the second part stores credentials as user ID/password pairs, encoded using base64.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论