当前位置: 代码迷 >> ASP.NET >> ================== 写过无数次的代码,信心受到很大的打击。有关Request.IsAuthenticated =============
  详细解决方案

================== 写过无数次的代码,信心受到很大的打击。有关Request.IsAuthenticated =============

热度:8022   发布时间:2013-02-25 00:00:00.0
================== 写过无数次的代码,自信心受到很大的打击。。。有关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 = "用户名或密码错误";
  相关解决方案