Ejemplo n.º 1
0
    public static void Check_Login()
    {
        bool       pBool      = false;
        string     strAccount = "";
        HttpCookie cookie     = HttpContext.Current.Request.Cookies["Account"];

        if (cookie != null)
        {
            strAccount          = cookie.Values["strAccount"].ToString();
            PageBase.strAccount = strAccount;
            if (strAccount != "")
            {
                pBool = true;
            }
        }
        //cookie.Values.Remove("strAccount");
        if (strAccount == "")
        {
            string    strIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            Cls_SQL   Sql   = new Cls_SQL();
            DataTable dt    = new DataTable();
            dt = Sql.selectTable("select top 1 U01I02UV0024 from U01 where U01I07CV0015 ='" + strIP + "'", "U01");
            try
            {
                if (dt.Rows.Count > 0)
                {
                    HttpCookie Cookie = new HttpCookie("Account");
                    DateTime   dtm    = DateTime.Now;
                    TimeSpan   ts     = new TimeSpan(1, 0, 0, 0);
                    Cookie.Expires = dtm.Add(ts);
                    Cookie.Values.Add("strAccount", dt.Rows[0]["U01I02UV0024"].ToString());
                    HttpContext.Current.Response.AppendCookie(Cookie);
                    pBool = true;
                    PageBase.strAccount = dt.Rows[0]["U01I02UV0024"].ToString();
                }
            }
            catch {
            }
        }
        if (pBool == false)
        {
            HttpContext.Current.Response.Redirect(PageBase.WebRoute + "/login.aspx");
        }
    }