Asp.net Cookies用法
来源:
发布时间:2010/8/21
浏览次数:871
创建Cookies
public void UserCookies()
{
if(Request.Browser.Cookies == true)
{
if(Request.Cookies["UserLogin"]==null)
{
HttpCookie UserCookie=new HttpCookie("UserLogin",DateTime.Now.ToString());
UserCookie.Value=Txt_Uname.Text;
UserCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(UserCookie);
Request.Cookies.Set(UserCookie);
}
}
}
退出
if(HttpContext.Current.Request.Cookies["UserLogin"]!=null)
{
HttpCookie UserCookie= Request.Cookies["UserLogin"];
UserCookie.Expires=DateTime.Now.AddDays(-1);
HttpContext.Current.Response.Cookies.Add(UserCookie);
}
判断Cookies是否为空
if(Request.Cookies["adminlogin"]==null)
{
....
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/liezuiwang/archive/2008/12/20/3558164.aspx