- 热门文章:
- · 如何在DataGrid控件中隐藏列
- · Common ASP.NET Code Techniques (DPC&DWCReference)--1
- · Common ASP.NET Code Techniques (DPC&dwc Reference)--2
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--3
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--4
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--5
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--6
- · 在datagrid中删除时确定(精华区的补充)
- · Displaying ListView items - with class! by Rob Birdwell
- · 一个带checkbox的webcontrol
- · 保护 XML Web 服务免受黑客攻击 [第一部分]
- · 保护 XML Web 服务免受黑客攻击, [第二部分]
上一篇:datalist分页(页面部分) >>
.net beta2 操作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(2001, 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>
----------------------------------------------------
come from Asp101.com
下一篇:如何在DataGrid控件中隐藏列 >>
相关文章:
- · treeview的源代码
- · 在datagrid中删除时确定?(转)
- · vs.net beta 2中利用DataGrid分页详解
- · COM组件对象与.NET类对象的相互转换
- · 关于DataGrid对象的属性设置(VB)
- · XmlNodeList
- · 用 FormsAuthentication.SetAuthCookie 做权限验证
- · 在datalist中选取数据。
- · Finding a Control Inside a Template
- · DataBinding DropDownList
- · 用asp.net向其他服务器post一条信息
- · Asp.net中用核选框显示数据的方法及ButtonColumn的使用方法
- · 如何在DataGrid控件中实现编辑、删除、分类以及分页操作
- · .NET框架类览胜( Ccident Net )
- · 使用JScript.NET创建asp.net页面(一)
- · 用Visual C#获得计算机名称和IP地址(转)
- · 据说可能是介绍 web.config 最详细的文章。大家参考参考[转]
- · 在ASP.NET中使用Session与Application 对象
- · 用asp.net实现将上传的图片变小存入数据库!(暑假里就开始想做的,很兴奋了)
- · 在ASP.NET中使用Session与Application 对象(续)
- · web.config 关于HttpHandlers 和HttpModules的使用实例【转】
- · 使用 sqlserver来存放和取得 session
- · session 和 viewstate 的比较
- · Online CPU Console using a Web Control Library with .NET Security(3)
- · Online CPU Console using a Web Control Library with .NET Security(2)
- · Online CPU Console using a Web Control Library with .NET Security(1)
- · 实现由web.config控制的验证
- · Passport 你的网站(在你的WebSite上实现MS Passport )上
- · Passport 你的网站(在你的WebSite上实现MS Passport )下
- · 利用ASP.NET来访问Excel文档
- · 如何把存储在数据库中的图片根据自己的需要的大小显示出来。【转】
- · Office XP Charting Examples in asp.net
- · 自定义控件的使用二----DBGlobal.cs部分
- · 自定义控件的使用例子一
- · 任意在datagrid里面添加控件。
- · 三、ASPNET中实现在线用户检测(使用后台守护线程)
- · 二、ASPNET中实现在线用户检测(使用后台守护线程)
- · ASPNET中实现在线用户检测(使用后台守护线程)
