Bonjour,
Je n'arrive pas a ecrire le cookie sur la machine cliente. Voici les symptomes:
Je cree le cookie, l'initialize avec des valeurs, j'utilise ces valeurs et tout va bien. Mais lorsque je ferme le navigateur et que je le rouvre, ce cookie devient NULL. Je n'arrive pas a le lire..(ou a l'ecrire ?) Savez vous pourquoi ?
Voici mon code :
///<summary>
/// Create the cookie if it does not exists.
///</summary>
privatevoid InitializeCookie()
{
// Check if the cookie exists
HttpCookie cookie = Request.Cookies[COOKIE_NAME];
if (cookie == null)
{
// Create a new cookie, passing the name into the constructor
cookie = newHttpCookie(COOKIE_NAME);
//Add the cookie on the user machine
Response.Cookies.Add(cookie);
}
}///<summary>
/// Sets the value to the cookie.
///</summary>
privatevoid SetCookieValue(string key, string value)
{
// Get the existing cookie
HttpCookie cookie = Request.Cookies[COOKIE_NAME];
// Set the value
cookie[key] = value;
// save the new value of the cookie
Response.Cookies.Add(cookie);
}
///<summary>
/// Gets the value corresponding with the given key. Returns False if the key is not found.
///</summary>
privatestring GetCookieValue(string key)
{
// Get the existing cookie
HttpCookie cookie = Request.Cookies[COOKIE_NAME];
// Set the value
if (cookie[key] == null)
returnfalse.ToString();
else
return cookie[key].ToString();
}
Merci pour votre aide!