在ASP.NET Core应用程序中,我具有如下代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options => ...)
.AddCookie()
.AddOpenIdConnect(options =>
{
...
options.Events = new OpenIdConnectEvents
{
...
OnAuthorizationCodeReceived = async context =>
{
// Here I want to access the user HttpContext. previously System.Web.HttpContext.Current
}
};
});
...
}
}
我需要访问当前用户HttpContext
的原因是,我正在处理一些AuthenticationContext.AcquireTokenByAuthorizationCodeAsync
逻辑,该逻辑在用户会话中缓存访问令牌。据了解,使用System.Web.HttpContext.Current
的先前代码版本已从ASP.NET Core中删除。 AuthorizationCodeReceivedContext.HttpContext
显然不是我想要的。
答案 0 :(得分:0)
context
代表的OnAuthorizationCodeReceived
参数包含保存当前http上下文的HttpContext
属性
OnAuthorizationCodeReceived = async context =>
{
var httpContext = context.HttpContext;
//..
}