私はOWINにとって全く新しく、この問題は私にとって大きな妨げになっています。私はセッションがnullであることをデバッグしていたときに、なぜHttpContext.Current.Session is null + OWIN
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
}
}
});
私は理解していない:
基本的に、私のMVCアプリで私は、スタートアップクラスで次のように持っています。 HttpContext.Currentプロパティはそうではありません。 Sessions + OWINに制約がありますか?この問題の回避策はありますか?どのようにそれにアプローチすべきですか?
注1サイド:
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();
});
サイド注2: Iドン私はSOの質問のいずれかに見つけたとセッションはまだヌルいたコードのこの部分を追加しようとしました もう見つからないようですが、誰かがSOの質問の1つで、空のメソッドSession_StartとSession_End(空のメソッドとして)をGlobal.asaxに追加するように提案しました。それはどちらもうまくいきませんでした。
私はアドバイスを歓迎しています。 ありがとう!
私も同様の問題があります。あなたはいくつかの解決策を見つけることができましたか? – RonakThakkar
こんにちは@RonakThakkar。残念ながら、まだです。私は何の解決策も見つけられなかったので、この仕事を脇に置かなければなりませんでした。うまくいけば、このスレッドで解決策が得られるかもしれません。 – AuroMetal