zigxag
Messages postés142Date d'inscriptionjeudi 10 février 2005StatutMembreDernière intervention 2 octobre 2008
-
14 déc. 2006 à 19:11
jesusonline
Messages postés6814Date d'inscriptiondimanche 15 décembre 2002StatutMembreDernière intervention13 octobre 2010
-
15 déc. 2006 à 00:38
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>
private
void 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 =
new
HttpCookie(COOKIE_NAME);
//Add the cookie on the user machine
Response.Cookies.Add(cookie);
}
}
///<summary>
/// Sets the value to the cookie.
///</summary>
private
void 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>
private
string GetCookieValue(
string key)
{
// Get the existing cookie
HttpCookie cookie = Request.Cookies[COOKIE_NAME];