/*
        Metodo que verifica que el usuario este autorizado en el active para ingresar al sistema
        */
        protected void buttonLogin_Click(object sender, EventArgs e)
        {
            String adPath = "LDAP://bsci.bossci.com"; //Fully-qualified Domain Name
            LdapAuthentication adAuth = new LdapAuthentication(adPath);
            try
            {
                if (true == adAuth.IsAuthenticated("BSCI", Login.Text, Password.Text))
                {
                    String groups = adAuth.GetGroups();

                    //Create the ticket, and add the groups.
                    bool isCookiePersistent = false;
                    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, Login.Text,
                    DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups);

                    //Encrypt the ticket.
                    String encryptedTicket = FormsAuthentication.Encrypt(authTicket);

                    //Create a cookie, and then add the encrypted ticket to the cookie as data.
                    HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                    if (true == isCookiePersistent)
                        authCookie.Expires = authTicket.Expiration;

                    //Add the cookie to the outgoing cookies collection.
                    Response.Cookies.Add(authCookie);

                    //Save data in server audit trail
                    InsertActionServerAuditTrailView view = new InsertActionServerAuditTrailView();
                    AuditService auditService = new AuditService();
                    String reason = "User Log In";
                    String user = Context.User.Identity.Name;
                    view.Reason = reason;
                    view.StationIP = General.getIp(this.Page);
                    view.UserName = Login.Text;
                    view.Action = "Login user";
                    view.NewValues = "N/A";
                    auditService.insertAuditTrail(view);

                    //Redirect now.
                    Response.Redirect("~/Default.aspx",false);
                }
                else
                {
                    errorLabel.Text = "Authentication did not succeed. Check user name and password.";
                }
            }
            catch (Exception ex)
            {
                errorLabel.Text = "Error authenticating. " + ex.Message;
            }
        }
Exemple #2
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (Page.IsValid == true)
            {

                string adDomain = "wilderness";
                string adPath = "LDAP://" + adDomain;

                LdapAuthentication adAuth = new LdapAuthentication(adPath);
                try
                {
                    if (true == adAuth.IsAuthenticated(adDomain, txtUsername.Text, txtPassword.Text))
                    {

                        string groups = adAuth.GetGroups();

                        //Create the ticket, and add the groups.
                        bool isCookiePersistent = chkPersist.Checked;
                        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups);

                        //Encrypt the ticket.
                        string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

                        //Create a cookie, and then add the encrypted ticket to the cookie as data.
                        HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                        if (true == isCookiePersistent)
                            authCookie.Expires = authTicket.Expiration;

                        //Add the cookie to the outgoing cookies collection.
                        Response.Cookies.Add(authCookie);

                        //You can redirect now.
                        Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, false));
                    }
                    else
                    {
                        cvLoginFail.ErrorMessage = "Authentication did not succeed. Check user name and password.";
                        cvLoginFail.IsValid = false;
                    }
                }
                catch (Exception ex)
                {
                    cvLoginFail.ErrorMessage = "Error authenticating. " + ex.Message;
                    cvLoginFail.IsValid = false;
                }
            }
        }