OWIN Cookie 身份验证不适用于 IIS 8.5
OWIN Cookie authentication not working on IIS 8.5
我开发了一个带有 OWIN 身份验证的 ASP.NET 网络应用程序,它在我的开发机器上运行良好 (Windows 10/IIS 10),但是当网络应用程序发布到我的 Windows 2012 server with IIS 8.5, cookie认证好像不行
当我登录(将 IsPersistent 设置为 true)并关闭浏览器时,当我再次启动浏览器时我仍然登录,所以没关系。但是当我重新启动IIS并启动浏览器时,我必须重新登录。
我创建了一个非常简单的应用程序来测试它,代码如下:
Startup.cs
public void ConfigureAuthentication(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login"),
CookieName = "ThisIsTheAuthCookie"
});
}
AuthenticationController.cs
public ActionResult Login(string userName, string password)
{
//For testing purposes every user/pwd is fine
var identity = new ClaimsIdentity(new [] { new Claim(ClaimTypes.Name, userName), },
DefaultAuthenticationTypes.ApplicationCookie,
ClaimTypes.Name, ClaimTypes.Role);
HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties { IsPersistent = true }, identity);
return RedirectToAction("index", "home");
}
甚至 Chrome 也显示了 cookie,但 OWIN 似乎没有在 IIS 8.5 上使用它:
有人知道问题出在哪里吗?
谢谢,
丹尼
你能尝试一些事情并分享结果吗:-
1.重启IIS,保留User-Agent。查看您现在是否已登录。
2. 在 Katana 中启用日志记录并在日志中检查此 warning/error。
已经有结果了吗?
对我来说,您似乎拥有带有可用会话 ID 的 cookie,但 IIS 服务器在该会话上不再感知。你确定你在 IIS 服务器上保持会话吗? (而不是 'In Process')
您可以在 IIS 配置中的会话状态下找到该选项。参见 TechNet Article IIS
问题已解决。我必须在 web.config!
中添加 MachineKey 元素
我开发了一个带有 OWIN 身份验证的 ASP.NET 网络应用程序,它在我的开发机器上运行良好 (Windows 10/IIS 10),但是当网络应用程序发布到我的 Windows 2012 server with IIS 8.5, cookie认证好像不行
当我登录(将 IsPersistent 设置为 true)并关闭浏览器时,当我再次启动浏览器时我仍然登录,所以没关系。但是当我重新启动IIS并启动浏览器时,我必须重新登录。
我创建了一个非常简单的应用程序来测试它,代码如下:
Startup.cs
public void ConfigureAuthentication(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login"),
CookieName = "ThisIsTheAuthCookie"
});
}
AuthenticationController.cs
public ActionResult Login(string userName, string password)
{
//For testing purposes every user/pwd is fine
var identity = new ClaimsIdentity(new [] { new Claim(ClaimTypes.Name, userName), },
DefaultAuthenticationTypes.ApplicationCookie,
ClaimTypes.Name, ClaimTypes.Role);
HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties { IsPersistent = true }, identity);
return RedirectToAction("index", "home");
}
甚至 Chrome 也显示了 cookie,但 OWIN 似乎没有在 IIS 8.5 上使用它:
有人知道问题出在哪里吗?
谢谢, 丹尼
你能尝试一些事情并分享结果吗:- 1.重启IIS,保留User-Agent。查看您现在是否已登录。 2. 在 Katana 中启用日志记录并在日志中检查此 warning/error。
已经有结果了吗?
对我来说,您似乎拥有带有可用会话 ID 的 cookie,但 IIS 服务器在该会话上不再感知。你确定你在 IIS 服务器上保持会话吗? (而不是 'In Process')
您可以在 IIS 配置中的会话状态下找到该选项。参见 TechNet Article IIS
问题已解决。我必须在 web.config!
中添加 MachineKey 元素