惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
A
About on SuperTechFans
Vercel News
Vercel News
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
V
Visual Studio Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
美团技术团队

博客园 - Jason.Yi

远程机器上无法用Assembly.Load(path).CreateInstance(ClassName)? - Jason.Yi - 博客园 vs2005代码区出现问题 吉他自录之《回忆组曲》 吉他自录之《爱的罗曼史》 求助:Vs2005 asp.net development server未能开始侦听端口 对Graphics.DrawImageUnscaledAndClipped的疑虑 哪些原因可能导致SQL操作操时呢? 二个算法题,大家有兴趣来看看 关于博客园的Calendar 费解的.net2.0中的ObjectDataSource控件 FormView在什么情况下自动生成模板项? 生成随机的颜色值 错误:已在多处定义 为什么本地sqlservr.exe进程占用内存如此之大? 这样的页面该如何实现? 简单的生成登录验证码的程序 遇到一个很奇怪的问题 连接SQL Server2005出错 能在web.config里做这样的配置吗?
为什么我的Cookie只能更新一个键值?
Jason.Yi · 2006-11-21 · via 博客园 - Jason.Yi

实在是想不到问题的所在了
//这个是来写/更新cookie的某一个键的
public static void WriteCookies(string key, string value)
    {
        if (value != null)
            value = HttpUtility.UrlEncode(value, Encoding.Default);
        HttpCookie cookie1 = HttpContext.Current.Request.Cookies[_cookie_name];
        if (cookie1 == null)
        {
            cookie1 = new HttpCookie(_cookie_name);
            cookie1.Values.Add(key, value);
            cookie1.Expires = DateTime.Now.AddYears(1);
            cookie1.Domain = Function.getModule().CookieDomain;
            HttpContext.Current.Response.Cookies.Add(cookie1);
            return;
        }
        cookie1.Values[key] = value;
        cookie1.Expires = DateTime.Now.AddYears(1);
        cookie1.Domain = Function.getModule().CookieDomain;
        HttpContext.Current.Response.Cookies.Set(cookie1);
    }
//这是得到当前cookie一个键的值
    public static string GetCookisValue(string key)
    {
        HttpCookie myCookie = HttpContext.Current.Request.Cookies[_cookie_name];
        if (myCookie != null)
        {
            if (myCookie.Values[key] != null)
                return HttpUtility.UrlDecode(myCookie.Values[key].ToString(),Encoding.Default);
            return "";
        }
        return "";
       
    }

调用该方法:
 global.WriteCookies("Name", _txt_username.Text.Trim());
 global.WriteCookies("Url", _homepage);

每次只更新了Url,却没有更新Name
跟踪时出现的怪现象是:
跟踪到第一个WriteCookies("Name","");时,更新正常,此时Name已被更新
跟踪到下一个WriteCookies("Url"......);时,却发现更新过的name键又还原了

这是当前页面的cookie
AJSTAT_ok_pages
AJSTAT_ok_times
CommentUser
Name=12345
Url=http%3a%2f%2fwww.123456c78.com
ASP.NET_SessionId

Name一直改不了,URl倒是可以更新

怪在调用同一方法,为什么只能更新第二个键?
请大家帮解一下