• ----:)欢迎访问源码网(:----
    • 首页
    • 博客
    • 学院
    • 下载
    • 论坛
    • 影视
    • 发布源码
    • RSS
    • ITPig
    • 笑话网
    • 百家姓
    • 繁體中文

源码网 - 中国第一源码门户
选择镜像:网通镜像 - 电信主站
  • 首 页
  • 新闻动态
  • 网站运营
  • 网页制作
  • WEB开发
  • 编程开发
  • 图像媒体
  • 操作系统
  • 数据库
  • 服务器
热门搜索 优化 SEO 故事 cms IIS7 MySQL 个人 AdSense 主题推广 | 文章搜索: 高级搜索
会员登录/控制面版您的位置: 学院首页 >> WEB开发 >> ASP开发 >> 系统相关 >> 详细内容
 

推荐文章

 
 

热点文章

  • ASP+中文教程
  • 展现 C#
  • ASP+上传文件语法
  • 如何在ASP+中发送邮件
  • asp+的几个特点
  • ASP控制计算机函数ADSI发表
  • asp+初体验---用c#写的asp+域名查询程序
  • ASP+中执行简单的Select查询,并返回数据表到DataGrid
  • ASP+数据库操作例子
  • ASP+ 跟踪
  • 一份ASP内存的释放的实验报告
  • ASP+页缓存OutputCache Duration用法
 
 

相关文章

  • ASP+中GetTitleAuthors和PutTitleAuthors应用例子
  • ASP+页缓存OutputCache Duration用法
  • ASP+中执行简单的Select查询,并返回数据表到DataGrid
  • 让您的主页支持各种浏览设备(ASP+篇)
  • ASP+培训教材
  • 如何在ASP+中发送邮件
  • ASP+数据库操作例子
  • 转换ASP到ASP+
  • asp+与asp的区别
  • 突破性的ASP+技术
  • asp+语法介绍
  • Active Server Pages + 介绍
 
 

百度搜索

 
 

在ASP+中使用Cookie

  • 阅览次数:
  • 文章来源: 网海之贝
  • 原文作者: 佚名
  • 整理日期: 2006-10-03
  • 发表评论
  • 字体大小:
  • 小
  • 中
  • 大

<%@ 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>
       

上一篇:PHP编程技巧:看实例学正则表达式
下一篇:构建支持Master/Slave读写分离的数据库操作类
  • 网友评论:
  • 查看所有评论
  • 我要发表评论
您的网名:
留言主题:
你要发表的内容:

 

关于本站 | 广告联系 | 版权声明 | 网站地图 | 发布软件 | 帮助中心 | 源码论坛

Copyright © 2005-2007 CodePub.Com  程序支持:木翼  滇ICP备05005971号