如何读取COOKIES
设置:
HttpCookie uid = new HttpCookie( "uid ", this.Users.GetUserId(LoginName).ToString());
uid.Expires = DateTime.Now.AddDays(1);
Response.SetCookie(uid);
Response.Redirect( "test.aspx ");
设置完成后,写个公用函数放在CODE页里
public bool IsLogin()
{
if (Request.Cookies[ "uid "].Value.ToString() != null && Request.Cookies[ "uid "].Value.ToString() != string.Empty)
{
return true;
}
else
{
return false;
}
}
然后在TEST.aspx页中调用该函数.
系统提示出错:
请求在此上下文中不可用
出错行是:if (Request.Cookies[ "uid "].Value.ToString() != null && Request.Cookies[ "uid "].Value.ToString() != string.Empty)
我该怎么办??
------解决方案--------------------HttpContext context = HttpContext.Current;
context.Request.Cookies[ "uid "].Value.ToString();