首页 >> 读书频道 >> 电脑 >> 在ASP+中使用Cookie
 
· 如何用asp进行base
· 如何在ASP中使用类
· 使用asp+中的若干问题
· 用ASP实现在特定的时段
· 让使用者可以看到你的AS
· 如何用ASP将一大段文字
· 用模板建立动态ASP页
· 使用ASP重启服务器
· 不刷新页面改变下拉菜单内
· 如何在ASP中通过ODB
· 如何用ASP建立图表
· ASP中文本文件与数据库
 
· 美容养颜手册
· 加油金顺剧情分集介绍完整
· 红楼梦:120回全本[清
· 素质教育在美国
· 全唐诗卷四十六
· 韩剧《布拉格恋人》剧情介
· 夜航船[作者:明·张岱]
· 局外人[作者:韩·可爱淘
· 现场流行病学
· 源氏物语[日本:紫式部]
· 武林寓言故事
· 2006高考录取规则
 
· (出租)中动商场部分及写
· (出租)中动动漫基地&#
· 喜剧学院
· 《善德女王》剧情介绍
· 魔女18号 剧情
· 丑女无敌剧情介绍
· 魔女幼熙剧情介绍
· 龙游天下剧情介绍
· 震撼世界的七日剧情介绍
· 静静的白桦林剧情介绍
· 心情日记—老公今天我想对
· 旗舰剧情介绍
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/

在ASP+中使用Cookie


查看有无更新版本

关键字:ASP技巧 2006-9-8

 

<%@ 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>
<h4>The 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="server" />
<p>
To see the cookie's current status you'll need to click below.  This is because the response
which adds or deletes the cookie happens after the request is already done.  As such, those changes aren't
available from the request collection until the next request.
</p>
<asp:Button type="submit" id="btnGetCookie" text="Get Cookie Details"
OnClick="btnGetCookie_OnClick" runat="server" />
</form>
<p>
<strong>Details of:</strong> <asp:label id="lblCookieDetails" runat="server" />
</p>
<table border="1">
<thead>
<tr>
<th>Property</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name</td>
<td><asp:label id="lblCookieDetailsName" runat="server" /></td>
</tr>
<tr>
<td>Value</td>
<td><asp:label id="lblCookieDetailsValue" runat="server" /></td>
</tr>
<tr>
<td>Expires</td>
<td><asp:label id="lblCookieDetailsExpires" runat="server" /></td>
</tr>
<tr>
<td>Domain</td>
<td><asp:label id="lblCookieDetailsDomain" runat="server" /></td>
</tr>
<tr>
<td>Path</td>
<td><asp:label id="lblCookieDetailsPath" runat="server" /></td>
</tr>
<tr>
<td>Secure</td>
<td><asp:label id="lblCookieDetailsSecure" runat="server" /></td>
</tr>
<tr>
<td>Has Keys</td>
<td><asp:label id="lblCookieDetailsHasKeys" runat="server" /></td>
</tr>
</tbody>
</table>
</body>
</html>

在ASP+中使用Cookie

[ 1 ]
在ASP+中使用Cookie num

打印本页 关闭

关于我们版权声明本站导航友情连结作品演示 TOP↑