蜜桃欧美|戒汤唯未删减版|先锋影音av资源在线观看|国产精品裸体一区二区三区,这么多年电影完整版免费在线观看,卧底2020电视剧免费全集在线观看,美好事物电影完整版在线观看

主營業(yè)務:網(wǎng)站制作 網(wǎng)站優(yōu)化 小程序制作 石家莊網(wǎng)站制作網(wǎng)站建設有限公司歡迎您!
石家莊閃云網(wǎng)絡科技有限公司
客服熱線15383239821
如何讓自己的網(wǎng)站更有質(zhì)量?

.NET內(nèi)置對象之Cookie對象

發(fā)布時間:2010/9/28 17:09:11

Cookie對象

Cookie對象是HttpCookieCollection類的一個實例,它用于保存客戶端瀏覽器請求的服務器頁面,也可以用它存取非敏感性的用戶信息,信息保存的時間可以根據(jù)需要設置。如果沒有設置Cookie失效日期,那么它們僅保存到關閉瀏覽器程序為止;如果將Cookie對象的Expires屬性設置為MinValue,則表示Cookie永遠不會過期。Cookie存儲的數(shù)據(jù)量很受限制,大多數(shù)瀏覽器支持的最大容量為4096字節(jié),因此,一般不要用來保存數(shù)據(jù)集或其他大量數(shù)據(jù)。由于并非所有的瀏覽器都支持Cookie,并且數(shù)據(jù)住處是以明文文本的形式保存在客戶端計算機中,因此最好不要保存敏感的、未加密的數(shù)據(jù),否則會影響網(wǎng)絡的安全性。

新建一個網(wǎng)站,包括一個網(wǎng)頁,代碼如下:

1、Default.aspx代碼:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>無標題頁</title>

</head>

<body>

<form id="form1" runat="server">

<div> 數(shù)據(jù)加密<br />

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

<asp:Button ID="Button2" runat="server" Text="數(shù)據(jù)加密" onClick="Button2_Click" /><br />

保存網(wǎng)站信息<br />

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

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

<asp:Button ID="Button3" runat="server" onClick="Button3_Click" Text="寫" Height="20px" Width="44px" />

&nbsp; &nbsp;<asp:Button ID="Button4" runat="server" Text="讀" Height="19px" onClick="Button4_Click" Width="58px" />

&nbsp; &nbsp;<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <br />

<asp:Button ID="Button1" runat="server" onClick="Button1_Click" Text="Button" /><br />

<asp:Label ID="Label1" runat="server" Height="14px" Text="Label" Width="358px"></asp:Label><br />

<asp:Label ID="Label2" runat="server" Height="13px" Text="Label" Width="358px"></asp:Label><br />

<asp:Label ID="Label3" runat="server" Height="9px" Text="Label" Width="356px"></asp:Label><br />

</div>

</form>

</body>

</html>

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}<br>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;

}

}

相關新聞推薦

在線客服 : 服務熱線:15383239821 電子郵箱: 27535611@qq.com

公司地址:石家莊市新華區(qū)九中街江西大廈4062

備案號:冀ICP備2022000585號-4