日期:2012-08-27  浏览次数:20450 次

<%@ Page Language="VB" %>

<script language="VB" runat="server">
    Const COOKIE_NAME  As String = "test-cookie-name"
    Const COOKIE_VALUE As String = "test-cookie-value"

    ' Declare our cookie object
    Dim objCookieObject As HttpCookie
    
    Sub btnSetCookie_OnClick(Sender As Object, E As EventArgs)
        ' Create a cookie object - I'm passing name and value,
        ' but you can also pass in a name and set the value later.
        ' ie. objCookieObject = New HttpCookie(COOKIE_NAME)
        objCookieObject = New HttpCookie(COOKIE_NAME, COOKIE_VALUE)

        ' We already set these above!
        'objCookieObject.Name   = COOKIE_NAME
        'objCookieObject.Value  = COOKIE_VALUE

        ' Additional cookie properties:
        objCookieObject.Expires = New DateTime(2010, 11, 12)

        ' Normally you can leave these alone.
        ' The defaults will work fine for most uses.
        'objCookieObject.Domain  = "www.domain.com"
        'objCookieObject.Path    = "/path/"
        'objCookieObject.Secure  = True
        
        Response.AppendCookie(objCookieObject)
    End Sub

    Sub btnRemoveCookie_OnClick(Sender As Object, E As EventArgs)
        objCookieObject = New HttpCookie(COOKIE_NAME)
        
        ' Expire it on the day I was born just so we're sure it's a date in the past.
        objCookieObject.Expires = New DateTime(1974, 11, 12)
        
        Response.AppendCookie(objCookieObject)
    End Sub

    Sub btnGetCookie_OnClick(Sender As Object, E As EventArgs)
        objCookieObject = Request.Cookies(COOKIE_NAME)

        ' In Beta 1 this worked fine... not with Beta 2.
        'If Not(objCookieObject = Nothing) Then
        
        If Not(objCookieObject Is Nothing) Then
            lblCookieDetails.Text        = objCookieObject.Name

            lblCookieDetailsName.Text    = objCookieObject.Name
            lblCookieDetailsValue.Text   = objCookieObject.Value
            
            ' For s