gpt4 book ai didi

c# - Cookie 不持久

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:22 25 4
gpt4 key购买 nike

我的 cookie 有问题。我通过 LDAP 对用户进行身份验证,只要浏览器保持打开状态,用户就不必重新登录该工具。只要浏览器打开,他们甚至可以关闭标签页。

但是当用户关闭浏览器时,cookie 就会被删除。我为此在谷歌上搜索了很多,但我无法找到任何解决方案,例如 this onethat one例如。

这是他们在我的登录页面上进行身份验证后的设置:

String encryptedTicket = FormsAuthentication.Encrypt(authTicket);

//Create a cookie, and then add the encrypted ticket to the cookie as data.
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

//Add expiration date to the cookie
authCookie.Expires = DateTime.Now.AddMonths(1);

//Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie);

//You can redirect now.
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);

我的 Web.Config 如下所示:

<authentication mode="Forms">
<forms loginUrl="Logon.aspx" timeout="43200" name="adAuthCookie" path="/" slidingExpiration="true" />
</authentication>

无论我做什么,ASP.NET_SessionId 和 adAuthCookie cookie 总是设置为“当我关闭浏览器时”过期。我想避免我的用户在关闭浏览器时总是必须登录,而是每月登录一次。

最佳答案

听起来您需要在 web.config 中设置一个 machineKey。如果未在此处或 machine.config 中指定,它将在启动时生成并在每次网站重新启动时重置,从而使 cookie 中的加密无效。

machineKey element

关于c# - Cookie 不持久,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5085530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com