繁体   English   中英

OWIN Cookie身份验证无法在IIS 8.5上运行

[英]OWIN Cookie authentication not working on IIS 8.5

我开发了一个带有OWIN身份验证的ASP.NET webapp,它在我的开发机器(Windows 10 / IIS 10)上工作正常,但是当使用IIS 8.5将webapp发布到我的Windows 2012服务器时,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日志记录并在日志中检查此警告/错误。

对此有任何结果吗?

对我来说,看起来你有可用会话ID的cookie,但IIS服务器在这个会话上不再知道。 您确定在IIS服务器上保留会话吗? (而不是'正在处理')

您可以在IIS配置中的“会话状态”下找到该选项。 请参阅TechNet文章IIS

问题已经解决了。 我不得不在web.config中添加MachineKey元素!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM