All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
不用改文件名,防止IIS文件被下载方法_[Asp.Net教程]
PHP学习宝典-第二章 (续篇)_[PHP教程]
SQL Server 2000 分布式事务错误解决_[SQL Server教程]
关于.NET中MD5加密与ASP中MD5加密值不同的解决办法_[Asp.Net教程]
Asp.Net对Xml文件的操作_[Asp.Net教程]
以xml数据源作无限级联动下拉框_[Asp.Net教程]
剖析SQL Server2005 SQLCLR代码安全性_[SQL Server教程]
利用UrlRewrite,asp.net动态生成htm页面(补充说明)_[Asp.Net教程]
HTML语言剖析(八)表单标记_[Html教程]
.NET2.0DataList分页_[Asp.Net教程]
Reading number is top 10 pictures
西班牙山村小景5
2012 national geographic daily picture8
心有鱼而力不足
yy365网站上的美女3
战场废物1
9.3阅兵全景图8-航空梯队
这酸爽,让人不敢相信
2012 national geographic daily picture7
The goddess of the single reason2
Absolutely shocked. National geographic 50 animal photographys2
Download software ranking
Jinling thirteen stock
XML+Web+Service开发教程
星际争霸1.08硬盘免安装版
White deer villiage
Unix video tutorial18
I'm come from Beijing1
C#与.NET技术平台实战演练
Call Of Duty2
中国结婚习俗实录
Such love down(擒爱记)
delv published in(发表于) 2014/1/27 6:45:23 Edit(编辑)
.NET内置对象之Cookie对象_[Asp.Net教程]

.NET内置对象之Cookie对象_[Asp.Net教程]

.NET内置对象之Cookie对象_[Asp.Net教程]

Cookie对象


Cookie对象是HttpCookieCollection类的一个实例,它用于保存客户端浏览器请求的服务器页面,也可以用它存取非敏感性的用户信息,信息保存的时间可以根据需要设置。如果没有设置Cookie失效日期,那么它们仅保存到关闭浏览器程序为止;如果将Cookie对象的Expires属性设置为MinValue,则表示Cookie永远不会过期。Cookie存储的数据量很受限制,大多数浏览器支持的最大容量为4096字节,因此,一般不要用来保存数据集或其他大量数据。由于并非所有的浏览器都支持Cookie,并且数据住处是以明文文本的形式保存在客户端计算机中,因此最好不要保存敏感的、未加密的数据,否则会影响网络的安全性。


新建一个网站,包括一个网页,代码如下:


1、Default.aspx代码:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





无标题页






数据加密




onClick="Button2_Click" />


保存网站信息



&nbsp; &nbsp; &nbsp;&nbsp;


onClick="Button3_Click" Text="写" Height="20px" Width="44px" />


&nbsp; &nbsp;onClick="Button4_Click" Width="58px" />


&nbsp; &nbsp;


onClick="Button1_Click" Text="Button" />













Default.aspx.cs代码:


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)


{



}


protected void Button1_Click(object sender, EventArgs e)


{


if (Request.Cookies["userInfo"] != null)


{


this.Label1.Text = Request.Cookies["userInfo"]["userName"];


this.Label2.Text = Request.Cookies["userInfo"]["lastVist"];


}


HttpCookie aCookie;


for (int i = 0; i < Request.Cookies.Count; i++)


{


aCookie = Request.Cookies[i];


this.Label3.Text = string.Format("Cookie 名称={0}
Cookie 值={1}", aCookie.Name, aCookie.Value);


}


}


protected void Button2_Click(object sender, EventArgs e)


{


string strPwd = TextBox1.Text;


Response.Cookies["strPwd"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(strPwd, "md5");


Response.Write(Response.Cookies["strPwd"].Value.ToString());


}


protected void Button3_Click(object sender, EventArgs e)


{


HttpCookie makecookie = new HttpCookie("Cookie");


makecookie.Value = this.TextBox2.Text;


Response.Cookies.Add(makecookie);


}


protected void Button4_Click(object sender, EventArgs e)


{


HttpCookie readcookie = Request.Cookies["cookie"];


this.TextBox3.Text = readcookie.Value;


}


}









添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.