标题:关于COOKIE的问题?
只看楼主
yangyanping0615
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-3-25
 问题点数:0 回复次数:1 
关于COOKIE的问题?

private void Page_Load(object sender, System.EventArgs e) {

string str="Persist Security Info=false;"; str+="user id=sa;password=sa;database=bbs;"; string sql="select * from users where username='"+username.Text+"'"; SqlConnection conn=new SqlConnection(str); SqlCommand cmd=new SqlCommand(sql,conn); DataSet ds=new DataSet(); SqlDataAdapter dr=new SqlDataAdapter(sql,conn); dr.Fill(ds,"users"); if (username.Text.Trim()=="") { message.Text="请输入你的姓名"; } else { if (ds.Tables["users"].Rows.Count==0) { message.Text="出错!"; } else { HttpCookie cookie = new HttpCookie ("login"); cookie.Value=username.Text; //UserName.Text是我的用户输入用户名TEXTBOX的值 Response.Cookies.Add(cookie); Response.Redirect("chklogin.aspx"); } } } 我在CHKLOGIN.ASPX中读不到cookie的值. public class chklogin : System.Web.UI.Page { protected System.Web.UI.WebControls.Label message; private void Page_Load(object sender, System.EventArgs e) { HttpCookie cookie = new HttpCookie ("login"); message.Text+=Request.Cookies["username"]; }

#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load);

} #endregion }

搜索更多相关主题的帖子: COOKIE 
2005-03-25 11:23
pietro
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2006-9-19
得分:0 
chklogin.aspx中的message.Text+=Request.Cookies["username"];错了,应该为:
message.Text+=Request.Cookies["login"].Value;
2006-12-07 15:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-14009-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016428 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved