在ASP+中使用Cookie

llisk

llisk

2016-01-29 18:10

在ASP+中使用Cookie,在ASP+中使用Cookie
  <%@ 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(2001, 12, 31, 23, 59, 59)

' 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)

If Not(objCookieObject = null) Then
lblCookieDetails.Text        = objCookieObject.Name

lblCookieDetailsName.Text    = objCookieObject.Name
lblCookieDetailsValue.Text   = objCookieObject.Value
lblCookieDetailsExpires.Text = objCookieObject.Expires.ToString
lblCookieDetailsDomain.Text  = objCookieObject.Domain
lblCookieDetailsPath.Text    = objCookieObject.Path
lblCookieDetailsSecure.Text  = objCookieObject.Secure.ToString
lblCookieDetailsHasKeys.Text = objCookieObject.HasKeys.ToString
Else
lblCookieDetails.Text        = "Cookie Not Set!"

lblCookieDetailsName.Text    = ""
lblCookieDetailsValue.Text   = ""
lblCookieDetailsExpires.Text = ""
lblCookieDetailsDomain.Text  = ""
lblCookieDetailsPath.Text    = ""
lblCookieDetailsSecure.Text  = ""
lblCookieDetailsHasKeys.Text = ""
End If

' I'm ignoring collections.  They're outside the realm of this basic sample.
' FYI: Additional properties related to cookie collections: Values, Item
End Sub
</script

<html
<body

<h4The cookie name we're using for this sample is: <em<%= COOKIE_NAME %</em</h4

<form action="cookies.aspx" method="post" runat="server"
<asp:Button type="submit" id="btnSetCookie" text="Set Cookie" OnClick="btnSetCookie_OnClick"
runat="server" /
<asp:Button type="submit" id="btnRemoveCookie" text="Remove Cookie"
OnClick="btnRemoveCookie_OnClick" runat="
展开更多 50%)
分享

猜你喜欢

在ASP+中使用Cookie

ASP
在ASP+中使用Cookie

在ASP中使用类

ASP
在ASP中使用类

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

在ASP中使用存储过程

ASP
在ASP中使用存储过程

在ASP中使用简单Java类

ASP
在ASP中使用简单Java类

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

在ASP中使用事务控制

ASP
在ASP中使用事务控制

在ASP中使用数据库

ASP
在ASP中使用数据库

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

如何在ASP中通过ODBC调用Excel中的数据

如何在ASP中通过ODBC调用Excel中的数据

Word学习之七:怎样在“打印预览”视图编辑文本?

Word学习之七:怎样在“打印预览”视图编辑文本?
下拉加载更多内容 ↓