Reputation: 2167
I have two variables which needs to be created as a cookie. Can I give them just as without giving any expiration date but just as a key value pair,
document.cookie = "<%= this.CookieDFKey %> = id";
alert (document.cookie);
document.cookie = "<%= this.CookieDateCompleteEnd %> = lastRunDate";
window.location = '<%= ResolveUrl("~/GUI/DRNEW.aspx") %>';
When I gave the alert statement to check what value it is having it shows me
I need to have both the values id and lastRunDate avaiable in the called page. Can I be just using Request.Cookie[the name of cookie where the value store]
?
Upvotes: 0
Views: 2951
Reputation: 59
document.cookie = "id=<%= this.CookieDFKey %>";
document.cookie = "lastRunDate=<%= this.CookieDateCompleteEnd %> ";
To retrieve cookie use the following code
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length,c.length);
}
}
return "";
}
Upvotes: 1
Reputation: 241
First cookies are key value pairs, you will get all cookies
in Request.Cookies
If i'm not wrong in C#
if (Request.Cookies["UserSettings"] != null)
{
string userSettings;
if (Request.Cookies["UserSettings"]["Font"] != null)
{ userSettings = Request.Cookies["UserSettings"]["Font"]; }
}
Read the below url to set multiple cookies in document.cookie
Setting multiple cookies in Javascript
Upvotes: 2