ASP.NET Core Identity 没有重定向到正确的登录页面
ASP.NET Core Identity does not redirect to correct logon pages
这样配置是行不通的。
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
options.LoginPath = $"/logon";
options.LogoutPath = $"/logoff";
options.AccessDeniedPath = $"/accessdenied";
options.SlidingExpiration = true;
})
以这种方式配置它正在工作:
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = "Caldr.Auth";
options.LoginPath = $"/logon";
options.LogoutPath = $"/logoff";
options.AccessDeniedPath = $"/accessdenied";
});
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
我希望两者具有相同的行为。显然不是。错误或我没有得到如何配置它? :-)
任何想法。
在发布我的问题时,我也有身份框架 configured/added。所以它可能是多种因素的混合,可能无法正常工作。
可行的解决方案:
配置:
var authenticationBuilder = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = $"/logon";
options.LogoutPath = $"/logoff";
options.AccessDeniedPath = $"/accessdenied";
});
ConfigureSocialLogins(authenticationBuilder);
实际登录(即写入 cookie 是通过)
private async Task SignInUser(AppUser appUser)
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, appUser.Email),
new Claim(ClaimTypes.Name, appUser.Displayname ?? appUser.Email),
new Claim(ClaimTypes.Email, appUser.Email),
};
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties());
}
记下CookieAuthenticationDefaults.AuthenticationScheme的所有用法。
这样配置是行不通的。
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
options.LoginPath = $"/logon";
options.LogoutPath = $"/logoff";
options.AccessDeniedPath = $"/accessdenied";
options.SlidingExpiration = true;
})
以这种方式配置它正在工作:
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = "Caldr.Auth";
options.LoginPath = $"/logon";
options.LogoutPath = $"/logoff";
options.AccessDeniedPath = $"/accessdenied";
});
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
我希望两者具有相同的行为。显然不是。错误或我没有得到如何配置它? :-)
任何想法。
在发布我的问题时,我也有身份框架 configured/added。所以它可能是多种因素的混合,可能无法正常工作。
可行的解决方案:
配置:
var authenticationBuilder = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = $"/logon";
options.LogoutPath = $"/logoff";
options.AccessDeniedPath = $"/accessdenied";
});
ConfigureSocialLogins(authenticationBuilder);
实际登录(即写入 cookie 是通过)
private async Task SignInUser(AppUser appUser)
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, appUser.Email),
new Claim(ClaimTypes.Name, appUser.Displayname ?? appUser.Email),
new Claim(ClaimTypes.Email, appUser.Email),
};
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties());
}
记下CookieAuthenticationDefaults.AuthenticationScheme的所有用法。