网站是用 asp.net core 2.1 编写的。
登录代码
ClaimsPrincipal principal = new ClaimsPrincipal(identity);
var authProperties = new AuthenticationProperties { };
if (isRemember)
{
authProperties = new AuthenticationProperties
{
ExpiresUtc = DateTimeOffset.UtcNow.AddDays(7),
IsPersistent = true
};
}
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, authProperties);startup.cs: ConfigureServices
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = new PathString("/Cn/Login");
options.Cookie.Name = ".demo";
options.Cookie.HttpOnly = true;
});startup.cs: Configure
app.UseAuthentication();本地测试都正常,七日之内都正常自动登录。但是、发布到服务器后 iis 下, 虽然 http 响应头信息带 之前登录的cookie信息, 只要重启该网站应用程序,登录失效,要求重新登录。这个怎么破?难道服务器环境要配置其他信息吗?
ps: 服务器环境 windows server 2012 r2 + IIS + .net core 2.1
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/658/viewspace-3168482/ ,如需转载,请注明出处,否则将追究法律责任。