0

I have a scenario where I am using a notification event in my client in the setup code is very simple as follows. This is a AspNet Mvc 4.72 client that uses AspNetCore IdentityServer4:

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
    ClientId = "members",
    ...
    Notifications = new OpenIdConnectAuthenticationNotifications
    {

        SecurityTokenValidated = notification =>
        {
            ... 
            // Sometimes this is null but I have to make sure it is 
            // always available so I can initialize stuff here.
            HttpContext.Current.<Use context here>;
            return Task.CompletedTask;
        }
    }
});

Actually, more specifically I need access to the session state but it doesn't matter there are some other needs directly related. I am not really sure why this happens but from my research it has something to do with SynchronizationContext and the lifetime of a AspNet Mvc request.

If anyone has a definitive answer about how to ensure the HttpContext's existence please let me know.

jwize
  • 4,230
  • 1
  • 33
  • 51

0 Answers0