私は、セッションSession.Add(「USEREMAIL」、txtUserNameを作成していますログインを作成し、このコードクッキーとセッション
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);
}
を使用してクッキーにユーザーの詳細を格納しています。値); 正常に認証された後、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>
は私を修正します。
Session["useremail"] = "[email protected]";
:そしてまた
あなたは 'BindGridView(Session [" useremail "]。ToString());感謝に(!Request.Cookiesは[FormsAuthentication.FormsCookieName] = NULL){ HttpCookie myCookie =新しいHttpCookie(FormsAuthentication.FormsCookieName)場合、私はクッキーを削除するには、このコードを使用していますそのため –
いや。 myCookie.Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(myCookie); } //FormsAuthentication.SignOut(); Response.Redirect( "Home.aspx");しかし、クッキーはそこにあり、私はuser.aspxページのログアウト方法を見ることができます – rookie