我创建一个登录和使用此代码Cookies和会话在asp.net
if (ValidateUser(txtUserName.Value,txtUserPass.Value))
{
//string useremail = Convert.ToString(txtUserName.Value);
Session.Add("useremail", txtUserName.Value);
FormsAuthenticationTicket tkt;
string cookiestr;
HttpCookie ck;
tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now,
DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, "your custom data");
cookiestr = FormsAuthentication.Encrypt(tkt);
ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
if (chkPersistCookie.Checked)
ck.Expires=tkt.Expiration;
ck.Path = FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(ck);
}
的存储在cookie中的用户的详细信息,我也创建一个会话Session.Add(“USEREMAIL”,txtUserName。值); 成功的身份验证后,它被重定向到user.aspx 我想读取user.aspx页面中的useremail值,但是当我尝试访问用户页面中的值时,它不显示useremail字段。
protected void Page_Load(object sender, EventArgs e)
{
if
(Session["useremail"] == null) Response.Redirect("Home.aspx");
else
BindGridView(useremail);
}
这是我的webconfig:
<authentication mode="Forms"><forms name=".YAFNET_Authentication" loginUrl="Home.aspx" protection="All" timeout="43200" cookieless="UseCookies"/></authentication>
纠正我,如果我做任何错误。也请告诉我如何将USEREMAIL值传递给user.aspx页面,这样我可以通过该值gridview的功能
难道你不是指'BindGridView(Session [“useremail”] .toString());'? –
是工作,谢谢 – rookie