如何自动记住登录名?
我这样写的,但是得到的是一串加密码而不是用户名的字符串,请问是什么原因[align=left] protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["myauthtest"] != null)
{
TextBox1.Text = Server.UrlEncode(Request.Cookies["myauthtest"].Value);
}
}[/align] --------------------编程问答-------------------- 你写入时 是不是加密了 --------------------编程问答--------------------
TextBox1.Text = Request.Cookies["myauthtest"].Value;
--------------------编程问答-------------------- 你只是访问cookies值,又不是url传值,用Server.UrlEncode干嘛, --------------------编程问答-------------------- 使用Server.HtmlEncode(Request.Cookies["myauthtest"].Value)也不行;
我使用的是身份验证票加密创建的COOKIE
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
TextBox1.Text,
DateTime.Now,
DateTime.Now.AddMinutes(1),
true,
reader.GetString(1),
FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
cookie.Expires = ticket.Expiration;
Response.Cookies.Add(cookie); --------------------编程问答-------------------- 如果你创建的时候编码了,读取的时候是解码
TextBox1.Text = Server.UrlDecode(Request.Cookies["myauthtest"].Value);
而不应当是 TextBox1.Text = Server.UrlEncode(Request.Cookies["myauthtest"].Value); --------------------编程问答-------------------- --------------------编程问答-------------------- 那我是不是不能使用COOKIE实现记住登录名了呢 --------------------编程问答-------------------- 仰望net_lover
编码和解码最好配对出现。
如果赋值没有编码,那获取值也用不作解码 --------------------编程问答-------------------- 解码应该解谁呢?FormsAuthentication.Decrypt(Request.Cookies["myauthtest"].Value).ToString()是不行的 --------------------编程问答-------------------- 我想在使用加密验证票创建COOKIE的前提下,实现记住登陆名,真的不能实现么,请教了
补充:.NET技术 , ASP.NET