【www.gdgbn.com--php常用代码】

asp教程写cookie代码


  "----------------------------------------------------------------
  " Name:  WriteCookie(ByVal strCookieName As String, ByVal strKeyName As String, ByVal strKeyValue As String)
  " Parameters:
  "  [ByVal] strCookieName - cookie名字
  "  [ByVal] strKeyName - 键名字
  "  [ByVal] strKeyValue - 键值。
  " Return:   String
  "----------------------------------------------------------------
  Public Function WriteCookie(ByVal strCookieName As String, ByVal strKeyName As String, ByVal strKeyValue As String) As String
    Dim objEnc As System.Text.Encoding = System.Text.Encoding.GetEncoding("GB2312")
    strKeyValue = System.Web.HttpUtility.UrlEncode(strKeyValue, objEnc)
    System.Web.HttpContext.Current.Response.Cookies(strCookieName)(strKeyName) = strKeyValue
  End Function

清除代码


  Sub CleanCookies()
    Dim i As Integer
    Dim cookie As System.Web.HttpCookie
    For i = 0 To System.Web.HttpContext.Current.Request.Cookies.Count - 1
    cookie = System.Web.HttpContext.Current.Request.Cookies(i)
    System.Web.HttpContext.Current.Response.Cookies(CStr(cookie.Name)).Value = ""
    System.Web.HttpContext.Current.Response.Cookies(CStr(cookie.Name)).Expires = DateAdd(DateInterval.Day, -1, Now)
    Next
  End Sub

本文来源:http://www.gdgbn.com/jiaocheng/23720/