Ich bin völlig neu zu OWIN und dieses Problem war ein wichtiger Blocker für mich.HttpContext.Current.Session ist null + OWIN
Grundsätzlich meinem MVC-app habe ich folgende bei Startup-Klasse:
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = OfficeSettings.ClientId,
Authority = OfficeSettings.Authority,
TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters()
{
RoleClaimType = "roles"
},
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthorizationCodeReceived = (context) =>
{
// code hidden for readability
if(HttpContext.Current.Session == null)
{
// It's null. Why is that?
}
var session = HttpContext.Current.Session;
if (session["myMockSession"] != null)
{
// Do stuff...
}
},
RedirectToIdentityProvider = (context) =>
{
// code hidden for readability
},
AuthenticationFailed = (context) =>
{
// code hidden for readability
}
}
});
Ich verstehe nicht, warum, wenn ich das Debuggen, dass die Session null ist. HttpContext.Current Property ist nicht. Gibt es Beschränkungen bei Sessions + OWIN? Gibt es eine Problemumgehung für dieses Problem? Wie sollte man es angehen?
Exkurs 1: Ich habe versucht, dieses Stück Code hinzufügen ich in einer der SO Fragen und die Session war noch null gefunden habe:
app.Use((context, next) =>
{
// Depending on the handler the request gets mapped to, session might not be enabled. Force it on.
HttpContextBase httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName);
httpContext.SetSessionStateBehavior(SessionStateBehavior.Required);
return next();
});
Exkurs 2: I don Es scheint nicht mehr zu finden, aber jemand schlug in einer der SO Fragen vor, die leeren Methoden Session_Start und Session_End (als leere Methoden) im Global.asax hinzuzufügen. Das hat auch nicht funktioniert.
Ich begrüße alle Hinweise. Danke!
Ich habe ähnliches Problem. Konnten Sie eine Lösung finden? – RonakThakkar
Hallo @RonakThakkar. Leider noch nicht. Ich musste diese Aufgabe beiseite legen, weil ich keine Lösung finden konnte. Vielleicht können wir hoffentlich in diesem Thread eine Lösung finden. – AuroMetal