In an ASP.NET Core App, I have code like the following:
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
}
};
});
...
}
}
My reason for needing access to the current User HttpContext
is that I'm dealing with some AuthenticationContext.AcquireTokenByAuthorizationCodeAsync
logic that caches access tokens in the user session. The previous version of the code used System.Web.HttpContext.Current
which I understand has been removed from ASP.NET Core. AuthorizationCodeReceivedContext.HttpContext
is clearly not what I'm looking for.
The context
parameter of OnAuthorizationCodeReceived
delegate contains HttpContext
property that holds current http context
OnAuthorizationCodeReceived = async context =>
{
var httpContext = context.HttpContext;
//..
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.