良い一日、コア2.0 SignInManager.IsSignedIn
私は、この問題で困惑しています。私のアプリは2つのサインインオプションを持っています(1つはAzure ADを内部ユーザ用に呼び出し、もう1つは外部ユーザ用にIDを使用して登録/ログインする)。 (私はアプリの主張データベースからADユーザーにクレームを追加するためにClaimsTransformer
を使用
私_LoginPartialは、次のようになります。これは、コア1.1で所望の効果を生み出し
@if (SignInManager.IsSignedIn(User))
{
... display @User.GetFirstName() and log out button
...
}
else if (User.Identity.IsAuthenticated)
{
... Display AD's @User.Claims.First(c => c.Type == ClaimTypes.GivenName).Value and sign out button
}
else
{
<ul class="nav navbar-nav ml-auto">
<li class="nav-item"><a asp-area="" asp-controller="Account" asp-action="Register" class="nav-link">Register</a>
</li>
<li class="nav-item"><a asp-area="" asp-controller="Account" asp-action="SignIn" class="nav-link">Internal Log in</a>
</li>
<li class="nav-item"><a asp-area="" asp-controller="Account" asp-action="Login" class="nav-link">External Log in</a>
</li> </ul>
}
しかし、今私が見えることはできません。外部のサインインのために以前に起こったことです(
SignInManager.IsSignedIn(User)
がtrueを返すように取得する
私Startup.cs
はそうのようになります。
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
...
})
.AddEntityFrameworkStores<JCContext>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/LogIn");
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
o.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddOpenIdConnect(option =>
{
option.ClientId = Configuration["Authentication:AzureAD:ClientId"];
option.Authority = Configuration["Authentication:AzureAd:Authority"];
option.CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"];
})
.AddCookie(o =>
{
o.LoginPath = new PathString("/Account/LogIn");
o.ExpireTimeSpan = TimeSpan.FromDays(150);
o.LogoutPath = "/Account/LogOut";
});
面白いのは、services.AddAuthentication(...)
の前にservices.AddIdentity
の前に置くと、逆の効果が得られます。私の外部ユーザーは「サインイン」を表示することができますが、はADユーザーのログイン時にtrue
を返しません。
起動時にアイテムを前後に並べ替えていますが、私は明白な何かを見逃していますか?私が理解していないSignInManager /クッキーに関するものがなければなりません。
ありがとうございました。
'App.UseIdentity'を' Configure'メソッドの 'app.UseAuthentication()'に置き換えましたか? – zulq
私は本当にありました。それはしばらくかかったが、私は最終的には、他のすべての作業を(今のところ!)得るために、アプリケーションをアップグレードしました。 – Mikustykus
多分あなた自身の質問に答えて将来他人を助けることができます。 – zulq