cookies对象的基本使用,COOKIES对象的属性

来源:互联网 发布:sql server有用吗 编辑:程序博客网 时间:2024/06/05 10:00

COOKIES对象的属性

属性            含义

all               传回所有的COOKIES

allkeys       传回所有的Cookies变量的名称到一个字符串型的数组

Count         传回Cookies变量的数量

Add             添加一个新的Cookie

Clear          清除所有的Cookie

Get              取得Cookies变量名称或者是索引值

remove       移去cookie

Set               更新Cookie的值

Expires       设定Cookie的时间,默认值为1000分钟。若值为0,则删除该Cookie

Name         取得Cookie变量的名称

Value          设定Cookie变量的值

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int i;
        Response.Cookies["cookies1"].Value="Microsoft";
        Response.Cookies["cookies2"].Value="Visual Studio.NET2005";
        for (i = 0; i < Request.Cookies.Count;i++ )
        {
            Response.Write("变量名称:"+Request.Cookies.Get(i).Name+"<br>变量内容:"+Request.Cookies.Get(i).Value+"<br>");
        }
        Response.Cookies.Clear();
    }

原创粉丝点击