【发布时间】:2019-08-24 02:43:11
【问题描述】:
在 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 显然不是我要找的。p>
【问题讨论】:
-
你的意思是
context.Request.HttpContext? -
或者只是
context.HttpContext。 -
@KirkLarkin @DavidG 这些与控制器公开的
HttpContexts 相同吗? (仅供参考,我只需要能够访问同一个会话)。 -
是的,应该是一样的。
标签: c# asp.net-core openid-connect