Saturday, May 5, 2012

asp.net Set Cookie for Client Pc using c#

   public void setCookie()
    {


        if ((chk_remember_me.Checked))
        {
            HttpCookie aCookie = new HttpCookie("mwa_gov_saChatInfo");
            Response.Cookies.Remove("mwa_gov_saChatInfo");
            Response.Cookies.Add(aCookie);
            aCookie.Values.Add("UserName",HttpUtility.UrlEncode(txtName.Value) );
            aCookie.Values.Add("Email", txtEmail.Value );
            aCookie.Expires = DateTime.Now.AddMonths(2);
            Response.Cookies.Add(aCookie);
        }
        else
        {
            HttpCookie cookie = Request.Cookies["mwa_gov_saChatInfo"];
            if (cookie != null)
            {
                HttpCookie aCookie = new HttpCookie("mwa_gov_saChatInfo");
                aCookie.Expires = DateTime.Now.AddMonths(-2);
                Response.Cookies.Add(aCookie);
                chk_remember_me.Checked = false;
            }
        }
    }

No comments:

Post a Comment