网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.如何用ASP编写网站统计系统一.
.ASP服务器组件编程心得.
.WEB打印设置解决方案四(在ASP中.
.如何安裝 IIS 5.0 ?.
.对连串英文自动换行的解决方法 I.
.图片循环显现.
.不能ASP图像组件来生成图像的ASP.
.个人经验:使用asp尽量减少服务器.
.正确处理ASP动态网页中的容错机制.
.ASP的Internet/Intranet编程常见.
.在ASP中自动创建多级文件夹的函数.
.ASP调用WEBSERVICE文档.
.ASP 中 Split 函数的实例.
.编写数据库操作类,使ASP.NET中的.
.介绍一种效率极高的分类算法.
.在Asp中如何快速优化分页的技巧.
.二十八条改善 ASP 性能和外观的技.
.利用global.asp定时执行ASP.
.利用ASP在浏览器上打印输出 .
.ASP错误的几种常规处理方式.

在ASP+中使用Cookie

发表日期:2000-11-13


<%@ 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进行base64加密 人气:14799
下一篇:asp+ 如何跨站抓取页面 人气:11148
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐