在 .NET Core 3.0 Api 中访问 http headers
Accessing http headers in .NET Core 3.0 Api
通过构造函数注入 IHttpContextAccessor。
private readonly IHttpContextAccessor _httpContextAccessor;
public Handler(IHttpContextAccessor httpContextAccessor)
{
_userManager = userManager;
_httpContextAccessor = httpContextAccessor;
}
//access header values.
var header = _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
通过构造函数注入 IHttpContextAccessor。
private readonly IHttpContextAccessor _httpContextAccessor;
public Handler(IHttpContextAccessor httpContextAccessor)
{
_userManager = userManager;
_httpContextAccessor = httpContextAccessor;
}
//access header values.
var header = _httpContextAccessor.HttpContext.Request.Headers["Authorization"];