Exemplo n.º 1
0
        protected void Session_Start(Object sender, EventArgs e)
        {
            if (HttpContext.Current.User != null)
            {
                // see if this user is authenticated, any authenticated cookie (ticket) exists for this user

                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    // see if the authentication is done using FormsAuthentication

                    if (HttpContext.Current.User.Identity is FormsIdentity)
                    {
                        Session["CurrentUser"] = AuthProvider.LoginWithDomain(HttpContext.Current.User.Identity.Name);
                        Session["CurrentUserId"] =
                            (new UsersDal()).GetUserGUIDByLogin(AuthProvider.LoginWithDomain(HttpContext.Current.User.Identity.Name));

                        var dal = new UsersDal();
                        dal.UsersStatisticsUpdateLoginCount(AuthProvider.UserKey(Session));
                    }
                }
            }

            // LoadBackGround
            var random = new Random();
            int randomNumber = random.Next(1, 8);
            Session["bg_image_url"] = string.Format("Images/layout/theme/bg{0}.jpg", randomNumber);
        }
Exemplo n.º 2
0
        protected void Unnamed1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            bool valid = false;
            using (var context = new PrincipalContext(ContextType.Domain))
            {
                var login = sender as System.Web.UI.WebControls.Login;
                if (login != null)
                {
                    valid = context.ValidateCredentials(login.UserName, login.Password);
                    if (valid)
                    {
                        var dal = new UsersDal();
                        var loginWithDomain = AuthProvider.LoginWithDomain(login.UserName);

                        if (!dal.IsUserExists(AuthProvider.LoginWithDomain(login.UserName)))
                        {
                            Session["CurrentUserId"] = dal.RegisterNewUser(loginWithDomain,
                                                         AuthProvider.GetUserFullNameByDomainIdentity(login.UserName));
                            Login1.DestinationPageUrl = "Profile.aspx";
                            //e.Authenticated = false;
                            //return;
                        }
                        else
                        {
                            Session["CurrentUserId"] = (new UsersDal()).GetUserGUIDByLogin(loginWithDomain);
                        }
                        Session["CurrentUser"] = loginWithDomain;

                        dal.UsersStatisticsUpdateLoginCount(AuthProvider.UserKey(Session));

                    }
                }
            }
            e.Authenticated = valid;
        }