cookie的问题和IE缓存

 

cookie的问题

#region 存取Cookie
    
/// <summary>
    
/// 存Cookie
    
/// Json Lee 2007-09-24
    
/// </summary>
    
/// <param name="strName">名称</param>
    
/// <param name="strValue"></param>
    
/// <param name="expDate">到期时间</param>
    
/// <returns></returns>        
    public void SetCookie(string cookieName, string cookieValue, int cookieExpiryMinute)
    {
        cookieName 
= cookieName.ToLower();
        HttpCookie cookie 
= new HttpCookie(cookieName,cookieValue);
        cookie.Expires 
= DateTime.Now.AddMinutes(cookieExpiryMinute);  //设置Cookie过期时间
        cookie.Path = "/";     
       
//设置可访问Cookie的路径 为项目下的cookie文件夹及其子文件夹下所有页面
        //如果需要整个应用程序可访问 则设置为cookie.Path = "/";即可 
        cookie.Domain 
= ".163.com";      
       
//以www.163.com为例,若要在 news.163.com等不同主机访问可以如上设置         

        
//删除旧的同名Cookie
        HttpContext.Current.Response.Cookies.Remove(cookieName);


        HttpContext.Current.Response.Cookies.Add(cookie);
    }

    
/// <summary>
    
/// 存Cookie
    
/// Json Lee 2007-09-24
    
/// </summary>
    
/// <param name="strName">名称</param>
    
/// <param name="strValue"></param>
    
/// <returns></returns>
    public void SetCookie(string cookieName, string cookieValue)
    {
        SetCookie(cookieName, cookieValue, 
60);
    }

    
/// <summary>
    
/// 清除Cookie
    
/// </summary>
    
/// <param name="strName">名称</param>
    
/// <returns></returns>
    public void ClearCookie(string cookieName)
    {
        SetCookie(cookieName,
"",-5);
    }

    
/// <summary>
    
/// 取Cookie
    
/// Json Lee 2007-09-24
    
/// </summary>
    
/// <param name="strName">名称</param>
    
/// <param name="strDefaultValue">当没有值的时候的默认值</param>
    
/// <returns></returns>
    public string GetCookie(string cookieName, string defaultValue)
    {
        cookieName 
= cookieName.ToLower();
        
string strResult = defaultValue;
        
try
        {
            
if (HttpContext.Current.Request.Cookies != null)
            {
                
if (HttpContext.Current.Request.Cookies[cookieName] != null)
                {
                    strResult 
= HttpContext.Current.Request.Cookies[cookieName].Value;
                }
            }
        }
        
catch (Exception ex)
        {
            
this.WriteWrongLog(ex);
        }

        
return strResult;
    }

    
/// <summary>
    
/// 取Cookie
    
/// Json Lee 2007-09-24
    
/// </summary>
    
/// <param name="strName">名称</param>
    
/// <returns></returns>
    public string GetCookie(string strName)
    {
        
return GetCookie(strName, "");
    }
    
#endregion


清除缓存private void Page_Load(object sender, System.EventArgs e)
        {
            
this.Response.Expires = 0;
        
        }
posted on 2007-11-16 09:43  活着的意义  阅读(216)  评论(0)    收藏  举报