public static bool CheckCookies()
 {
     if (HttpContext.Current.Session[SessionId] == null)
     {
         if (HttpContext.Current.Request.Cookies[CS._CurrentLoginTime] != null && HttpContext.Current.Request.Cookies[CS._PrevVisit] != null)
         {
             string cl_user  = HttpContext.Current.Request.Cookies[CS._CurrentLoginTime].Value;
             string ltocu    = HttpContext.Current.Request.Cookies[CS._PrevVisit].Value;
             var    dtCookie = new LoginCookie()
             {
                 CookieClUser = cl_user, CookieLtocu = ltocu
             }.Select(new LoginCookie()
             {
                 CookieExpireTime = IndianDateTime.Now
             });
             if (dtCookie.Rows.Count > 0 && Convert.ToDateTime(dtCookie.Rows[0][CS.CookieExpireTime]) > IndianDateTime.Now)
             {
                 if (!IsValidUsersId(CC.DecryptCookies(cl_user, ltocu)))
                 {
                     HttpContext.Current.Response.Redirect("Logout.aspx?" + CS.rurl.Encrypt() + "=" + HttpContext.Current.Request.Url.ToString().Encrypt());
                 }
                 else
                 {
                     WriteSession(int.Parse(CC.DecryptCookies(cl_user, ltocu)));
                     return(true);
                 }
             }
         }
         return(false);
     }
     else
     {
         return(true);
     }
 }
    public static void CheckSession(bool IsRedirect)
    {
        if (HttpContext.Current.Request.QueryString["UserName"] != null &&
            HttpContext.Current.Request.QueryString["Password"] != null)
        {
            LoginUtilities.LoginIfValid(HttpContext.Current.Request.QueryString["UserName"].ToString(), HttpContext.Current.Request.QueryString["Password"].ToString(), true);
        }

        if (HttpContext.Current.Session[SessionId] == null)
        {
            if (HttpContext.Current.Request.Cookies[CS._CurrentLoginTime] != null && HttpContext.Current.Request.Cookies[CS._PrevVisit] != null)
            {
                string cl_user = HttpContext.Current.Request.Cookies[CS._CurrentLoginTime].Value;
                string ltocu   = HttpContext.Current.Request.Cookies[CS._PrevVisit].Value;

                var dtCookie = new LoginCookie()
                {
                    CookieClUser = cl_user, CookieLtocu = ltocu
                }.Select(new LoginCookie()
                {
                    CookieExpireTime = IndianDateTime.Now
                });
                if (dtCookie.Rows.Count > 0 && Convert.ToDateTime(dtCookie.Rows[0][CS.CookieExpireTime]) > IndianDateTime.Now)
                {
                    if (!IsValidUsersId(CC.DecryptCookies(cl_user, ltocu)))
                    {
                        if (IsRedirect)
                        {
                            HttpContext.Current.Response.Redirect("Logout.aspx?" + CS.rurl.Encrypt() + "=" + HttpContext.Current.Request.Url.ToString().Encrypt());
                        }
                    }
                    else
                    {
                        WriteSession(int.Parse(CC.DecryptCookies(cl_user, ltocu)));
                    }
                }
                else
                {
                    if (IsRedirect)
                    {
                        HttpContext.Current.Response.Redirect("Login.aspx?" + CS.rurl.Encrypt() + "=" + HttpContext.Current.Request.Url.ToString().Encrypt());
                    }
                }
            }
            else
            {
                if (IsRedirect)
                {
                    HttpContext.Current.Response.Redirect("Login.aspx?" + CS.rurl.Encrypt() + "=" + HttpContext.Current.Request.Url.ToString().Encrypt());
                }
            }
        }

        CU.GetMasterPageLabel("lblMstUsersId").Text = CU.GetUsersId().ToString();
    }