中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > .NET > ASP.NET
asp+ 操作Cookie 方法大全
作者:未知 时间:2006-07-28 11:53 出处:不详 责编:月夜寒箫
              摘要:asp+ 操作Cookie 方法大全
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Const COOKIE_NAME As String = "豆腐站点"
Const COOKIE_VALUE As String = "http://www.asp888.net"
' 声明 Cookie 对象
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.

 

objCookieObject = New HttpCookie(COOKIE_NAME, COOKIE_VALUE)

' 另外的一种操作Cookie 的 方法
'objCookieObject = New HttpCookie(COOKIE_NAME)
'objCookieObject.Name = COOKIE_NAME
'objCookieObject.Value = "sdsd"

' 设置Cookie 的 过期时间 2001/12/31 23:59:59
objCookieObject.Expires = New DateTime(2001, 12, 11, 23, 59, 59)

' 下面的这些可以不使用
objCookieObject.Domain = "www.asp888.net"
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)
' 删除Cookie
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
End Sub
</script>

<html>
<head>
<title> asp+ 操作Cookie 方法大全 </title>
</head>
<body>

<h4>我们设置的Cookie 的名称是: <em><%= COOKIE_NAME %></em></h4>

<form 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>
想要看看 Cookie 的当前的各个属性,请点击下面的按钮
</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>Cookie属性</th>
<th>Cookie 的属性Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>名称</td>
<td><asp:label id="lblCookieDetailsName" runat="server" /></td>
</tr>
<tr>
<td>Cookie的值</td>
<td><asp:label id="lblCookieDetailsValue" runat="server" /></td>
</tr>
<tr>
<td>过期时间</td>
<td><asp:label id="lblCookieDetailsExpires" runat="server" /></td>
</tr>
<tr>
<td>所在域</td>
<td><asp:label id="lblCookieDetailsDomain" runat="server" /></td>
</tr>
<tr>
<td>路径</td>
<td><asp:label id="lblCookieDetailsPath" runat="server" /></td>
</tr>
<tr>
<td>安全性</td>
<td><asp:label id="lblCookieDetailsSecure" runat="server" /></td>
</tr>
<tr>
<td>主键</td>
<td><asp:label id="lblCookieDetailsHasKeys" runat="server" /></td>
</tr>
</tbody>
</table>

</body>
</html>

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有