日期:2014-05-17 浏览次数:20510 次
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);
}
}
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
&n