首页 > 解决方案 > Asp.net (MVC) 身份验证 cookie 在重定向时丢失 - 但仅在 Firefox 上

问题描述

在这个上挠头。我设置了一个身份验证 cookie,然后进行了重定向,除了 Firefox,一切正常。我可以看到 cookie 被添加,但在重定向完成后被删除。这在本地主机上的 Edge、Chrome、Safari 和 Firefox 上运行良好,但仅在 Azure 服务器上的 Firefox 上失败。有任何想法吗?

        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
            0,                                      // ticket version
            userid,                                 // authenticated user id
            DateTime.Now,                           // Issue date
            DateTime.Now.AddDays(1),         // Expiration date
            true,                                  // true to persist across browser sessions
            "",                               // can be used to store additional user data
            FormsAuthentication.FormsCookiePath);   // path         

        // Encrypt the ticket using the machine key
        string cipherText = FormsAuthentication.Encrypt(ticket);
        if (null != cipherText)
        {
            // Add the cookie to the request to save it
            cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cipherText);
            //cookie.Path = FormsAuthentication.FormsCookiePath;
            cookie.Secure = true;

            FormsAuthentication.SetAuthCookie(userid, true);
        }

        Response.Redirect("~/app/dashboard", false);

更新:

所以多挖一点。这部署在 azure 上,实际上在部署槽上工作,但在生产中失败(使用 Firefox)。当我交换插槽(重新映射 IP 地址)时,应用程序不再工作(cookie 不再存在)。

标签: c#asp.net-mvcazureauthenticationcookies

解决方案


推荐阅读