为什么读不到Cookies的值??

anan221 2009-03-11 12:45:38
if (this.txtname.Text == "" || this.txtmobile.Text == "")
{
Response.Write("<script>");
Response.Write("alert('请输入您的姓名和手机号码!')");
Response.Write("</script>");
Response.Write("<script>window.location.replace('login.aspx')</script>");
}
HttpCookie readcookie = System.Web.HttpContext.Current.Request.Cookies["Username"];
HttpCookie readcookiemobile = System.Web.HttpContext.Current.Request.Cookies["Usermobile"];
HttpCookie readcookieid = System.Web.HttpContext.Current.Request.Cookies["Userid"];
if (!Object.Equals(readcookie, null) && !Object.Equals(readcookiemobile, null))
{
//HttpCookie readcookie = Request.Cookies["Username"];
//HttpCookie readcookiemobile = Request.Cookies["Usermobile"];
//HttpCookie readcookieid = Request.Cookies["Userid"];
string name = this.txtname.Text.Trim();
string mobile = this.txtmobile.Text.Trim();
if ((name == readcookie.Value) && (mobile == readcookiemobile.Value))
{
Session["id"] = readcookieid.Value;
Session["name"] = readcookie.Value;
Session.Timeout = 24 * 60;
Response.Write("<script>window.location.replace('singleExam.aspx?type=1')</script>");
}
else
{
Response.Write("<script>");
Response.Write("alert('系统未搜索到您的有效信息,请重新核对!')");
Response.Write("</script>");
Response.Write("<script>window.location.replace('login.aspx')</script>");
}
}
else
{
Response.Write("<script>alert(readcookie.Value)</script>");
}

这样的代码没有错吧,怎么取不到Cookies的值,在本地是好的,在服务器上就是读不到值,难道是Username是中文的有关???
...全文
170 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
anhao2008 2009-03-11
  • 打赏
  • 举报
回复
Cookic的Value是Object的吧
delphi_new 2009-03-11
  • 打赏
  • 举报
回复
哎,楼主强人啊
anan221 2009-03-11
  • 打赏
  • 举报
回复
终于被我搞出来了,HttpCookie cookie = new HttpCookie("Username");
cookie.Value = HttpUtility.UrlEncode(this.txtname.Text.Trim(), Encoding.GetEncoding("GB2312"));
cookie.Expires = DateTime.MaxValue;
Response.AppendCookie(cookie);

写的时候中文转化一下,读取的时候再转化下
if ((name == HttpUtility.UrlDecode(readcookie.Value, Encoding.GetEncoding("GB2312"))) && (mobile == readcookiemobile.Value))
{
}

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧