日期:2014-05-18  浏览次数:20346 次

cookies问题
HttpCookie myCookie = new HttpCookie("Miser");
myCookie["UserName"] = decrypt_encrypt.Encrypt(UserName, decrypt_encrypt.myKey);
myCookie["Pass"] = decrypt_encrypt.Encrypt(Pass1, decrypt_encrypt.myKey);
myCookie.Expires = DateTime.Now.AddDays(10);
Response.Cookies.Add(myCookie);

我用这个方法创建了COOKIES 然后我跳转页面 创建的COOKIES就自动消失了 这是怎么回事啊?

------解决方案--------------------
response.cookies.append(cookie);
------解决方案--------------------
C# code

using System;
using System.Web;

namespace Showwin.Common.Web
{
    /// <summary>
    /// Cookies 的摘要说明。
    /// </summary>
    public class Cookies
    {
        public static string Get(string Key)
        {
            string s = string.Empty;

            if(System.Web.HttpContext.Current.Request.Cookies[Key] != null)
            {
                s = System.Web.HttpContext.Current.Request.Cookies[Key].Value;
            }
            return s;
        }

        #region Set
        public static void Set(string Key,string Value,bool SaveFlag)
        {
            HttpCookie cookie = new HttpCookie(Key,Value);
            cookie.Path="/";
            if(SaveFlag)
            {
                cookie.Expires = DateTime.Now.AddDays(365);
            }
            System.Web.HttpContext.Current.Response.AppendCookie(cookie);
        }
        public static void Set(string Key,string Value)
        {
            Set(Key,Value,false);
        }
        #endregion
        
        #region Remove
        public static void Remove(string Key)
        {
            System.Web.HttpContext.Current.Response.Cookies[Key].Expires = DateTime.Now.AddDays(-1);
        }
        #endregion
    }
}

------解决方案--------------------
response.cookies.append(cookie);
这样可以
------解决方案--------------------
HttpCookie cookie = new HttpCookie("cookie2");
cookie.Values.Add("CheckCode", checkCode);
Response.Cookies.Add(cookie);
LZ可以这样试试
------解决方案--------------------
Response.Cookies.Add(myCookie); 
改为
Response.AppendCookie(myCookie);
试试~~