Пример #1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //Performs Windows authentication
                    if (MSDNSWebAdmin.AppCode.WindowsAuthentication.Authenticate(model.UserName, model.Password, model.Domain))
                    {
                        Session["Username"] = model.UserName;
                        Session["Password"] = model.Password;
                        Session["Domain"]   = model.Domain;

                        //Log successful login
                        Audit.Log(Audit.AuditTypeEnum.Login, System.Environment.MachineName, (model.Domain) + "\\" + (model.UserName), NetworkHelper.ClientIPAddress(HttpContext), "Logged on", "", "");

                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        Audit.Log(Audit.AuditTypeEnum.Login, System.Environment.MachineName, (model.Domain) + "\\" + (model.UserName), NetworkHelper.ClientIPAddress(HttpContext), "Login failed", "", "");
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    //Log failed Login
                    Audit.Log(Audit.AuditTypeEnum.Login, System.Environment.MachineName, (model.Domain) + "\\" + (model.UserName), NetworkHelper.ClientIPAddress(HttpContext), "Login failed", "", "");

                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }



            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #2
0
        // **************************************
        // URL: /Account/LogOff
        // **************************************
        public ActionResult LogOff()
        {
            Audit.Log(Audit.AuditTypeEnum.Login, System.Environment.MachineName, (Session["Domain"] as string) + "\\" + (Session["Username"] as string), NetworkHelper.ClientIPAddress(HttpContext), "Logged off", "", "");

            Logger("Account", "LogOff").InfoFormat("User {0} Logged off", Session["Username"]);

            Session.Abandon();

            return(RedirectToAction("Index", "Home"));
        }