title: Cookie expiration time not working in C#
body: <p>I cannot set a persistent cookie. It become session only.</p>
  
  <p>I know the same problem have asked <a href="https://stackoverflow.com/questions/8973628/cookies-expiration-not-working-in-c-sharp">here</a> but I couldn't fix it even I did all the steps.<br />
  (Couldn't have test with Fiddler).</p>
  
  <p>My code is:</p>
  
  <pre><code>/// Default.aspx.cs methods :
  
  protected void Page_Load(object sender, EventArgs e)
  {
      if (! Cookies.CookieExist("kuki"))
      {
          Cookies.CreateCookie("kuki");
      }
      Fill();
  }    
  
  private void Fill()
  {
      string a = Cookies.GetCookieValue("kuki", "key");
  
      if (!a.Contains("data"))
      {
          return;
      }
      // codes for a
  }
  
  protected void ButtonAdd_Click(object sender, EventArgs e)
  {
      if (TextBox1.Text != string.Empty)
      {
          Cookies.InsertCookie("kuki", "key", TextBox1.Text);
      }        
  }
  
  
  /// Cookie class methods:
  
  public static void InsertCookie(string Cookie, string Key, string Data)
  {
      HttpCookie Kuki = HttpContext.Current.Request.Cookies[Cookie];
      Kuki[Key] = Data;
      HttpContext.Current.Response.SetCookie(Kuki);
  }
  
  public static bool CookieExist(string Cookie)
  {
      HttpCookie cookie = HttpContext.Current.Request.Cookies[Cookie];
      if (cookie == null)
      {
          return false;
      }
      else
      {
          return true;
      }
  }
  
  public static void CreateCookie(string Cookie)
  {
      HttpCookie cookie = new HttpCookie(Cookie);
      cookie.Expires = DateTime.Now.AddYears(1);
      HttpContext.Current.Response.Cookies.Set(cookie);
  }
  
  public static string GetCookieValue(string CookieName, string CookieKey)
  {
      HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieName];
      try
      {
          if (cookie != null)
          {
              return cookie[CookieKey].ToString();
          }
          else
          {
              return "";
          }
      }
      catch (Exception)
      {
          return "";
      }        
  }
  </code></pre>
  
  <p>I use Chrome.<br />
  How can I fix this ?</p>
  
  <p>Update:</p>
  
  <p>Added button and InsertCookie methods.</p>