================== 写过无数次的代码,自信心受到很大的打击。。。有关Request.IsAuthenticated =============
已经将代码放到这里.
https://skydrive.live.com/redir?resid=4D9CD22D50108C94!165
很简单的登录功能。环境visual studio 2012 ,4.5 framework,iis express
public static class Users
{
private static readonly List<Tuple<string, string, string>> vals;
static Users()
{
vals = new List<Tuple<string, string, string>>();
vals.Add(new Tuple<string, string, string>("userName", "pwd", "group1"));
}
public static Tuple<string, string, string> Login(string userName, string pwd)
{
return vals.FirstOrDefault(x => x.Item1 == userName && x.Item2 == pwd);
}
}
login.aspx登录页
protected void btnOk_Click(object sender, EventArgs e)
{
var result = Users.Login(userName.Text,pwd.Text);
if (result != null)
{
string userDataString = result.Item3;
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName.Text, RememberMe.Checked);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userDataString);
authCookie.Value = FormsAuthentication.Encrypt(newTicket);
Response.Cookies.Add(authCookie);
string redirUrl = FormsAuthentication.GetRedirectUrl(userName.Text, RememberMe.Checked);
Response.Redirect(redirUrl);
}
else
{
lblmsg.Text = "用户名或密码错误";
}
}
登录后的页面main.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
FormsIdentity ident = User.Identity as FormsIdentity;
if (ident != null)
{
FormsAuthenticationTicket ticket = ident.Ticket;
string userDataString = ticket.UserData;
lblmsg.Text = userDataString;
}
}
else
{
lblmsg.Text = "请求未通过验证";
}
}
Request.IsAuthenticated这里总是返回false.
自信心受到很大的打击。。
各位朋友帮忙看看
[解决办法]
完了 2010的打不开。。http://blog.csdn.net/heker2007/article/details/2162349