- 热门文章:
- · Net中如何操作IIS(原理篇)
- · 关于选用何种ASP.NET设计方法的技巧
- · .Net中如何操作IIS(源代码) (原创)
- · iis 坏掉了,重新安装了以后.netframework 不能用了的解决方法
- · 两个aspx页面间传递引用对象。
- · 在Webcontrol的Toolbar上加入删除确认的方法(改进后)
- · TreeView 派生类: TreeViewEx 实现 NodeShowToolTip、NodeDoubleClick 事件
- · 我自己写的自定义Web的上传控件
- · 增加判断文字长度,汉字算2个
- · 客户端脚本对中文的验证(javascript)
- · 献丑了,我的asp.net网站开发经验,欢迎参加讨论。
- · 笑望人生,关于IHttpHandler处理图片
上一篇:VB.NET开发互联网应用 >>
vb.net cookie操作
<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 some reason I@#m having trouble with this now...
@# The setting seems to work, but I can@#t read it back.
@# Anyone have any ideas? Email me -> john@asp101.com
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="cookie.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>
下一篇:Net中如何操作IIS(原理篇) >>
相关文章:
- · HTML在线编辑器--服务器控件~~.NET实现~~
- · How to Share Session State Between Classic ASP and ASP.NET(1)
- · How to Share Session State Between Classic ASP and ASP.NET(2)
- · 关于验证控件,希望对和我原来有疑惑的朋友有帮助(刚找的资料,结合猫猫的)
- · 上次的一个问题我打了微软的求助电话,他们也没有办法!
- · [技巧]DataGird的hyper column的url field 绑定两个字段
- · ms--help
- · 续
- · Simple Paging in Repeater and DataList Controls
- · ASP.NET编程中的十大技巧(建议进精华)
- · 转贴:DataGrid/DataList
- · 用ASP.NET写你自己的代码生成器(1)。
- · ASP.NET中Cookie编程的基础知识(6)
- · ASP.NET中Cookie编程的基础知识(5)
- · ASP.NET中Cookie编程的基础知识(4)
- · ASP.NET中Cookie编程的基础知识(3)
- · ASP.NET中Cookie编程的基础知识(2)
- · ASP.NET中Cookie编程的基础知识(1)
- · .NET中窗体间相互访问的几种方式
- · .net中PictureBox中图片的拖动
- · 在.NET上如何根据字符串动态创建控件
- · .NET 窗体之间的交互
- · 使用UltraWinGrid时双击的处理
- · .Net 下的Wondows窗体常用项目
- · 在.net中实现与ASP完全兼容的MD5算法(包括中文字符)
- · .Net FrameWork SDK文档的例子演示
- · 利用.NET语言开发自己的脚本语言(一)
- · .NET中的数据类型的一些变化
- · 网上发现的文章(测试驱动开发)
- · .NET程序实现多语言
- · .NET Framework中使用XML Web Service(2)
- · .NET Framework中使用XML Web Service(1)
- · 管理三元式的新思路,涉及到查询时似乎可以借用Social Network的思想
- · 使用AOP微型框架的例子
- · VB.NET中使用FTP下载文件的两种方法
- · .net下基于API封装的DirectUIHWND窗体访问
- · 在.net中调用存储过程的另一种方法
- · .NET Remoting 实现分布式数据库查询
