asp.net考前复习——状态管理
Application状态管理
Application["number"]=0;
Application["number"]=(int)Application["number"]+1;
Session状态管理
this.Label2.Text=Session["who"].ToString();
Session["who"]=this.TextBox1.Text;
Application与Session的区别:Application传递对所有页面都适用的数据,Session传递对特定的连接适用的数据。
状态信息保存在进程外
1)、保存在状态服务器
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="false"
timeout="20"/>
</sessionState>
2)、保存在数据库
<sessionState mode="SQLServer" sqlConnectionString="data source=(local);user id=sa;password=" />
cookie
//定义cookie,设置其值
HttpCookie objCookie = new
HttpCookie("myCookie");
objCookie.Values.Add("BackColor",
"Blue");
objCookie.Expires =
DateTime.Now.AddHours(1);
Response.Cookies.Add(objCookie);
//使用cookie
HttpCookie objCookie =
Request.Cookies["myCookie"];
Button1.BackColor=System.Drawing.Color.FromName(objCookie.Values["BackColor"]);
-------------------------------------------------
!!!作者:木由水 http://www.cnblogs.com/muyoushui