I'm currently working with chrome Version 67, the cookie management view changes a lot.
pls refer to the following article for some basic operation
https://developers.google.com/web/tools/chrome-devtools/manage-data/cookies
the trick is, the cookies listed here are ONLY those which are eligible for the current page. e.g.: Cookies which has a Path property to some other pages, will not be listed here.
tips: show all cookies for a site:
input the following to address bar
chrome://settings/cookies/detail?site=<your sit>
e.g. chrome://settings/cookies/detail?site=localhost
-----------------------------------------------------------------------------------------------
cookies can also be manipulated on console via javascript:
1. list cookies
document.cookie
2. add cookie
document.cookie="cookieName=value"
cookie with a value of key-value pairs:
document.cookie = "myCookie=" + JSON.stringify({foo: 'bar', baz: 'poo'});
note: if multiple cookies need to be added, call for each
document.cookie="cookieName1=value1"
document.cookie="cookieName2=value2"
3. Delete a cookie,
cookie can be delete by setting "expires" ahead of present.
document.cookie = 'cookieName=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'
---------------------------
tricks from chrome:
all those above operation will be attached with an additional parameter implicitly:
path=/<currentPath>
if you
a. add cookie on a page
b. go to another page
c. list cookies
the cookie just added will not be shown, coz the path is different
best practice on Chrome DevTools
always specify the "path" when handling cookies
add:
document.cookie="name=value;path=/"
delete:
document.cookie = 'name=; expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/'
-------------------------------------
C# code to manipulate cookies in controller
a) read cookie
var cookie = Request.Cookies["<name>"];
if(cookie != null)
{
cookie.Value;//single valued cookie
cookie.Values["key1"];//valued as key-value pairs
}
b) delete cookie
to delete the cookie from the client side, by adding a expired cookie to response, and then tell the browser to delete it.
string cookieName = "name";
if(Request.Cookies[cookieName ] != null)
{
HttpCookie myCookie = new HttpCookie(cookieName );
myCookie.Expires = new DateTime(1970, 1, 1);
Response.Cookies.Add(myCookie);
}
note that, in C# code, when calling new HttpCookie(), the default Path is the root, '/'