Cookie對(duì)象
Cookie對(duì)象是HttpCookieCollection類的一個(gè)實(shí)例,它用于保存客戶端瀏覽器請(qǐng)求的服務(wù)器頁(yè)面,也可以用它存取非敏感性的用戶信息,信息保存的時(shí)間可以根據(jù)需要設(shè)置。如果沒有設(shè)置Cookie失效日期,那么它們僅保存到關(guān)閉瀏覽器程序?yàn)橹梗蝗绻麑ookie對(duì)象的Expires屬性設(shè)置為MinValue,則表示Cookie永遠(yuǎn)不會(huì)過(guò)期。Cookie存儲(chǔ)的數(shù)據(jù)量很受限制,大多數(shù)瀏覽器支持的最大容量為4096字節(jié),因此,一般不要用來(lái)保存數(shù)據(jù)集或其他大量數(shù)據(jù)。由于并非所有的瀏覽器都支持Cookie,并且數(shù)據(jù)住處是以明文文本的形式保存在客戶端計(jì)算機(jī)中,因此最好不要保存敏感的、未加密的數(shù)據(jù),否則會(huì)影響網(wǎng)絡(luò)的安全性。
新建一個(gè)網(wǎng)站,包括一個(gè)網(wǎng)頁(yè),代碼如下:
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>無(wú)標(biāo)題頁(yè)</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>
<asp:Button ID="Button3" runat="server" onClick="Button3_Click" Text="寫" Height="20px" Width="44px" />
<asp:Button ID="Button4" runat="server" Text="讀" Height="19px" onClick="Button4_Click" Width="58px" />
<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;
}
}
?石家莊網(wǎng)站建設(shè)的優(yōu)點(diǎn):我們是專屬定制,制作符合您公司業(yè)務(wù)、風(fēng)格的網(wǎng)站,這就做到給您制作的網(wǎng)站是網(wǎng)絡(luò)上獨(dú)一無(wú)二的網(wǎng)站,這樣更有利于搜索引擎的收錄。如果您喜歡網(wǎng)絡(luò)上某個(gè)風(fēng)格的網(wǎng)站或者網(wǎng)站模板,我們是只仿制而不直接套用,我們會(huì)對(duì)其中的結(jié)構(gòu)和樣式做增減優(yōu)化,做…
?競(jìng)價(jià)排名營(yíng)銷是一種通過(guò) 競(jìng)價(jià)購(gòu)買搜索引擎中關(guān)鍵詞或關(guān)鍵短語(yǔ)的廣告方式。競(jìng)價(jià)排名營(yíng)銷分為兩種類型。 第一種,直接為真正的搜索引擎結(jié)果的排名付費(fèi),也就是說(shuō)付的錢越多,網(wǎng)頁(yè)所獲得的排名名也就越高。 第二種則更類似于普通的廣告。這種競(jìng)價(jià)排名營(yíng)銷方式通過(guò)…
?網(wǎng)站優(yōu)化對(duì)網(wǎng)站來(lái)說(shuō)是非常重要的,直接決定和影響著網(wǎng)站所起到的作用,以及在各個(gè)地方當(dāng)中的排名。在進(jìn)行seo優(yōu)化的過(guò)程中,我們必須要堅(jiān)持一定的原則,真正的把這些事情做得更好,才可以確保最終的結(jié)果,這對(duì)于我們來(lái)說(shuō)是非常重要的事。 SEO優(yōu)化主要分為8小步: …