Ejemplo n.º 1
0
        public ActionResult LogOut()
        {
            LoginUserDetails objLoginUserDetails = (LoginUserDetails)Common.Common.GetSessionValue(ConstEnum.SessionValue.UserDetails);

            if (objLoginUserDetails != null)
            {
                Dictionary <string, DocumentDetailsDTO> dicDocumentDetailsDTO = objLoginUserDetails.DocumentDetails;
                if (dicDocumentDetailsDTO != null && dicDocumentDetailsDTO.Count > 0)
                {
                    string directory = ConfigurationManager.AppSettings["Document"];
                    foreach (KeyValuePair <string, DocumentDetailsDTO> objDocumentDetailsDTO in dicDocumentDetailsDTO)
                    {
                        if (System.IO.File.Exists(Path.Combine(directory, "temp", objDocumentDetailsDTO.Key)))
                        {
                            FileInfo file = new FileInfo(Path.Combine(directory, "temp", objDocumentDetailsDTO.Key));
                            file.Delete();
                        }
                    }
                }
                using (SessionManagement sessionManagement = new SessionManagement())
                {
                    //sessionManagement.CheckCookiesSessions(objLoginUserDetails, false, (System.Web.HttpRequest)System.Web.HttpContext.Current.Request, (System.Web.HttpResponse)System.Web.HttpContext.Current.Response, "LOGOUT");
                    sessionManagement.BindCookiesSessions(objLoginUserDetails, false, (System.Web.HttpRequest)System.Web.HttpContext.Current.Request, (System.Web.HttpResponse)System.Web.HttpContext.Current.Response, "LOGOUT");
                }

                using (var objUserInfoSL = new UserInfoSL())
                {
                    objUserInfoSL.DeleteFormToken(objLoginUserDetails.CompanyDBConnectionString, Convert.ToInt32(objLoginUserDetails.LoggedInUserID), 0);
                    objUserInfoSL.DeleteCookiesStatus(objLoginUserDetails.CompanyDBConnectionString, Convert.ToInt32(objLoginUserDetails.LoggedInUserID), "Delete");
                }
            }

            //expire cookies use for validation
            Response.Cookies[ConstEnum.CookiesValue.ValidationCookies].Expires = DateTime.Now.AddYears(-1);

            //expire all other cookies, if any
            if (Response.Cookies.Count > 0)
            {
                foreach (string cookies_name in Response.Cookies.AllKeys)
                {
                    if (cookies_name != ConstEnum.CookiesValue.ValidationCookies)
                    {
                        Response.Cookies[cookies_name].Expires = DateTime.Now.AddYears(-1);
                    }
                }
            }

            if (Session["IsSSOActivated"] != null && Session["IsSSOActivated"].ToString() == "1")
            {
                CompanyDTO objSelectedCompany = null;
                using (CompaniesSL objCompanySL = new CompaniesSL())
                {
                    objSelectedCompany = objCompanySL.getSingleCompanies(Common.Common.getSystemConnectionString(), objLoginUserDetails.CompanyName);
                    ViewBag.SSOUrl     = objSelectedCompany.sSSOUrl;
                }

                ClearAllSessions();
                return(View("Logout"));
            }
            ClearAllSessions();

            TempData["ShowCaptcha"] = false;
            TempData.Remove("ContactDetails");
            TempData.Remove("RelativeMobileDetail");
            return(RedirectToAction("Login", "Account"));
        }