Cookie CSharp and jquery

jquery.cookie
Create session cookie:
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
Read cookie:
$.cookie('the_cookie'); // => "the_value"
$.cookie('not_existing'); // => undefined
Read all available cookies:
$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" }
Delete cookie:
// Returns true when cookie was found, false when no cookie was found...
$.removeCookie('the_cookie');

// Same path as when the cookie was written...
$.removeCookie('the_cookie', { path: '/' });

Using HttpCookie class
Add the cookie
HttpCookie myCookie = new HttpCookie("MyTestCookie");
DateTime now = DateTime.Now;

// Set the cookie value.
myCookie.Value = now.ToString();
// Set the cookie expiration date.
myCookie.Expires = now.AddMinutes(1);

// Add the cookie.
Response.Cookies.Add(myCookie);

Read the cookie
HttpCookie myCookie = Request.Cookies["MyTestCookie"];
if(myCookie != null)
{
   if(!string.IsNullOrWhiteSpace(myCookie.Value))
   {
       string cookieValue = myCookie.Value;
   }
}

using CookieContainer Class
CookieContainer cookieContainer = new CookieContainer();
cookieContainer.Add(new Cookie("name1", "value1", "/", "domain.com"));
cookieContainer.Add(new Cookie("name2", "value1", "/path1/", "domain.com"));
cookieContainer.Add(new Cookie("name2", "value1", "/path1/path2/", "domain.com"));
cookieContainer.Add(new Cookie("name1", "value1", "/", "domain.com"));
cookieContainer.Add(new Cookie("name2", "value1", "/path1/", "domain.com"));
cookieContainer.Add(new Cookie("name2", "value1", "/path1/path2/", "domain.com"));
Cookie CSharp and jquery Cookie CSharp and jquery Reviewed by Bhaumik Patel on 8:45 PM Rating: 5