Cookie的运用
1.使用Cookie对象保存和读取客户端信息
string UserIP = Reuqest.UserHostAddress.ToString();//获取客户端的IP地址
Response.Cookies["IP"].Value = UserIP; //将客户端的IP地址保存在Cookies对象中
Response.Cookies["IP"].Expires = DataTime.MaxValue; //设计Cookies的失效期
Response.Write(Request.Cookies["IP"].Value); //从Cookies中读取客户端IP地址值
-->string LOGON_USER = Request.ServerVariables["LOGIN_USER"].Trim(); //获取登录名 QCS./Michael.Cheng
LOGON_USER=LOGON_USER.Substring(LOGON_USER.IndexOf("//")+1,LOGON_USER.Length-LOGON_USER.IndexOf("//")-1); //截取,Michael.Cheng
HttpCookie Cookie = new HttpCookies("OAM"); //新建OAM 的Cookie
Response.Cookies["OAM"].Expires = new System.DateTime(2015,8,20); //设置Cookie的有效期到2015年8月20日
Cookie.Values.Add("OAMUserName",LOGON_USER); //把登录名赋值给OAMUserName
//Response.Cookies["OAMUserName"].Value = LOGON_USER; //效果同上
Response.Cookies.Add(Cookie);
Response.Redirect("Menu/**.Asp");
**.Asp
If session("login_user_id") ="" then
Dim ck
Set ck = Request.Cookies("OAM");
If Not (ck is Nothing) then
Session("login_user") =ck("OAMUserName")
End If
End If