C# Cookie(修改/替换问题)
我无法从服务器端修改存储在 cookie 中的 SessionKey 的最后一个值。下一个请求中的 SessionKey 仍然具有旧值。我的服务器端代码有什么问题?
var varHttpListenerContextResponseCookie_SessionKey =
refHttpListenerContext.Response.Cookies[Constants.Cookies.LongNames.SessionKey];
if (varHttpListenerContextResponseCookie_SessionKey != null)
{
varHttpListenerContextResponseCookie_SessionKey.Value = refSessionKey;
}
else
{
refHttpListenerContext.Response.AppendCookie(
new System.Net.Cookie(Constants.Cookies.LongNames.SessionKey, refSessionKey));
}
请帮我!:)
I cannot modify last value of SessionKey which stored in cookies from server side. SessionKey in next request is still has old value. What wrong in my server's side code?
var varHttpListenerContextResponseCookie_SessionKey =
refHttpListenerContext.Response.Cookies[Constants.Cookies.LongNames.SessionKey];
if (varHttpListenerContextResponseCookie_SessionKey != null)
{
varHttpListenerContextResponseCookie_SessionKey.Value = refSessionKey;
}
else
{
refHttpListenerContext.Response.AppendCookie(
new System.Net.Cookie(Constants.Cookies.LongNames.SessionKey, refSessionKey));
}
Please help me!:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要更新值
MSDN - ASP.NET 中的 Cookie 基础知识
You must remember to add your modified cookie to Response if you want to update value
MSDN - Basics of Cookies in ASP.NET
据我了解,您想修改您的会话密钥。如果正确,那么您可以使用 SessionManager,它可以让您创建新的会话密钥。如果这不是您想要的,请提供有关您的问题的更多详细信息。
谢谢,
Shashi
如果您的问题得到解答,请将其标记为“已解答”。
From my understanding you want to modify your session Key. If it is right then you can make use of SessionManager, which will let you create a new session key. If this is not what you wanted please give more details about your question.
Thanks,
Shashi
If your question is answered kindly mark it as Answered.
另外,在修改/添加 cookie 时,不要忘记创建/增加过期时间,因为过期的 cookie 可能无法检索
Also when modifying/adding a cookie, don't forget to create/increase the expiration, as expired cookies may not be retrievable