• CooieHelper类,方法 清除cookie退出登录



    /// <summary> /// 为HttpCookie创建kye,hash存cookie对象的key和值 /// </summary> /// <param name="strKey"></param> /// <param name="hash"></param> public static void AddCookie(string strKey, Hashtable hash) { HttpCookie cookie = HttpContext.Current.Request.Cookies[strKey]; if (cookie != null) { cookie.Expires = DateTime.Now.AddDays(-1); HttpContext.Current.Response.Cookies.Add(cookie); } if (hash != null) { cookie = new HttpCookie(strKey); foreach (DictionaryEntry de in hash) { cookie.Values.Add(de.Key.ToString(), de.Value.ToString()); } cookie.Expires = DateTime.Now.AddHours(5); HttpContext.Current.Response.Cookies.Add(cookie); } } /// <summary> /// 判断cook对象是否为空 /// </summary> /// <param name="strKey"></param> /// <returns></returns> public static HttpCookie GetCookie(string strKey) { HttpCookie cookie = HttpContext.Current.Request.Cookies[strKey]; if (cookie != null) { return cookie; } else { return null; } }
    
    
    /// <summary>
    ///推出清除Cookie
    /// </summary>
    protected void LinkExit_Click(object sender, EventArgs e)
    {

        HttpCookie cookie = Request.Cookies["employee"];

    if (cookie != null)
    {
    cookie.Expires = DateTime.Today.AddDays(-1);
    Response.Cookies.Add(cookie);
    }
    Response.Redirect("../Login.aspx");

    }
  • 相关阅读:
    洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers
    celery -2
    【express】
    ↗☻【HTML5秘籍 #BOOK#】第8章 使用CSS3
    -_-#【Dom Ready / Dom Load】
    【jQuery】
    ♫【Avalon】
    【兼容】IE下PNG色差
    ↗☻【HTML5秘籍 #BOOK#】第4章 Web表单
    洛谷—— P1328 生活大爆炸版石头剪刀布
  • 原文地址:https://www.cnblogs.com/chenghu/p/2526015.html
Copyright © 2020-2023  润新知