asp.net考前複習——狀態管理

來源:互聯網
上載者:User

12.0pt;line-height:125%">Applicationline-height:125%;font-family:宋體;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>狀態管理

Application["number"]=0;

Application["number"]=(int)Application["number"]+1;

 

 

 

12.0pt;line-height:125%">Sessionline-height:125%;font-family:宋體;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>狀態管理

 this.Label2.Text=Session["who"].ToString();

 Session["who"]=this.TextBox1.Text; 

 

12.0pt;line-height:125%;color:red">Application12.0pt;line-height:125%;font-family:宋體;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman";color:red'>與Session"Times New Roman";mso-hansi-font-family:"Times New Roman";color:red'>的區別:Application"Times New Roman";mso-hansi-font-family:"Times New Roman";color:red'>傳遞對所有頁面都適用的資料,Session"Times New Roman";mso-hansi-font-family:"Times New Roman";color:red'>傳遞對特定的串連適用的資料。

 

 

狀態資訊儲存在進程外

12.0pt;line-height:125%">1)125%;font-family:宋體;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:
"Times New Roman"'>、儲存在狀態伺服器 

12.0pt;line-height:125%"><sessionState mode="StateServer"  stateConnectionString="tcpip=127.0.0.1:42424"   cookieless="false"
timeout="20"/>

</sessionState>

 12.0pt;line-height:125%">2)125%;font-family:宋體;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:
"Times New Roman"'>、儲存在資料庫

line-height:125%">

<sessionState mode="SQLServer"
sqlConnectionString="data source=(local);user id=sa;password=" />

 

 

125%">cookie 

12.0pt;line-height:125%">//125%;font-family:宋體;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:
"Times New Roman"'>定義line-height:125%">cookiefont-family:宋體;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:
"Times New Roman"'>,設定其值line-height:125%">

12.0pt;line-height:125%;color:red">HttpCookie objCookie = new
HttpCookie("myCookie");

12.0pt;line-height:125%;color:red">objCookie.Values.Add("BackColor",
"Blue");

12.0pt;line-height:125%;color:red">objCookie.Expires =
DateTime.Now.AddHours(1);

12.0pt;line-height:125%;color:red">Response.Cookies.Add(objCookie);

12.0pt;line-height:125%">

 

12.0pt;line-height:125%">//125%;font-family:宋體;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:
"Times New Roman"'>使用line-height:125%">cookie

12.0pt;line-height:125%;color:red">HttpCookie objCookie =
Request.Cookies["myCookie"];

Button1.BackColor=System.Drawing.Color.FromName(objCookie.Values["BackColor"]); 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.