private static AuthSession RefreshInternal()
        {
            try
            {
                var _session = new AuthSession
                {
                    UserId   = int.Parse(SessionExtensions.Get(SessionExtensions.key_UserId)),
                    UserName = SessionExtensions.Get(SessionExtensions.key_UserName)
                };

                return(_session);
            }
            catch (Exception ex)
            {
                throw new Exception(HttpStatusCode.Unauthorized.ToString());
            }
        }
Exemple #2
0
        public static string Login(string userName, string password)
        {
            using (Entities _db = new Entities())
            {
                var hashedPwd = AuthSuport.GetMD5(password);
                var user      = _db.tbUsers.Where(x => x.UserName.Trim() == userName && x.Password.Trim() == hashedPwd).FirstOrDefault();
                if (user == null)
                {
                    return("Invalid UserName or Password.");
                }

                SessionExtensions.Set(SessionExtensions.key_UserId, user.ID.ToString());
                SessionExtensions.Set(SessionExtensions.key_UserName, user.UserName);

                //FormsAuthentication.SetAuthCookie(user.UserName, true);
                //FormsAuthentication.SetAuthCookie(user.ID.ToString(), true);
                //var value = FormsAuthentication.GetAuthCookie(user.UserName, true);
                //var value1 = FormsAuthentication.GetAuthCookie(user.ID.ToString(), true);

                return("true");
            }
        }