Remove Cookie - CSharp System.Web

CSharp examples for System.Web:Cookie

Description

Remove Cookie

Demo Code


using System.Web;
using System.Text;
using System.Net;
using System.Linq;
using System.Configuration;
using System.Collections.Generic;
using System;//  ww w.  j a va 2s  . c  o m

public class Main{
        public static void RemoveCookie(string cookieName, string key)
        {
            HttpResponse response = HttpContext.Current.Response;
            if (response != null)
            {
                HttpCookie cookie = response.Cookies[cookieName];
                if (cookie != null)
                {
                    if (!string.IsNullOrEmpty(key) && cookie.HasKeys)
                        cookie.Values.Remove(key);
                    else
                        response.Cookies.Remove(cookieName);
                }
            }
        }
        public static void RemoveCookie(string cookieName)
        {
            RemoveCookie(cookieName, null);
        }
}

Related Tutorials