1. 程式人生 > >退出登入方法,清除相關的cookies和session

退出登入方法,清除相關的cookies和session

        /// <summary>
        /// 退出登入
        /// </summary>
        public void LoginOut()
        {
            Session.Abandon();
            if (Request.Cookies["loginId"] != null && Request.Cookies["pwd"] != null && Request.Cookies["id"] != null)
            {
                Response.Cookies["id"].Expires = DateTime.Now.AddYears(-10);
                Response.Cookies["loginId"].Expires = DateTime.Now.AddYears(-10);
                Response.Cookies["pwd"].Expires = DateTime.Now.AddYears(-10);
            }
            Response.Write("<script> top.location.href='Login.aspx'; </script>");
        }