SORU
19 Ocak 2009, PAZARTESİ


ASP MVC Çerezler kalıcı değil

Ve çerezleri kaydetmek almak için görünüşte basit bir kod ile ASP MVC Uygulaması var ama nedense ısrar etmezler. Kontrol kodu

if (System.Web.HttpContext.Current.Response.Cookies["CountryPreference"] == null)
{
    HttpCookie cookie = new HttpCookie("CountryPreference");
    cookie.Value = country;
    cookie.Expires = DateTime.Now.AddYears(1);
    System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
}

Ve yeniden yüklemek için :

if (System.Web.HttpContext.Current.Request.Cookies["CountryPreference"] != null)
{
    System.Web.HttpContext.Current.Request.Cookies["CountryPreference"].Expires = DateTime.Now.AddYears(1);
    data.Country = System.Web.HttpContext.Current.Request.Cookies["CountryPreference"].Value;
}

Nedense kurabiye her zaman null olur?

CEVAP
26 ŞUBAT 2009, PERŞEMBE


Sorun kodu aşağıdaki yatıyor:

if (System.Web.HttpContext.Current.Response.Cookies["CountryPreference"] == null)

Cookie kullanarak bir Yanıt varlığı kontrol etmeye çalıştığınızda nesne yerine İstek, ASP.net otomatik olarak bir çerez oluşturur.

Bu ayrıntılı yazı burada kontrol edin: http://chwe.at/blog/post/2009/01/26/Done28099t-use-ResponseCookiesstring-to-check-if-a-cookie-exists!.aspx


Bağlantıyı tekrar aşağı düşerse makaleden alıntı....

Eğer ... Eğer ... kısa açıklama, tüm hikayeyi okumak gibi

Eğer kodu gibi kullanırsanız “ (Yanıt.[“”] Mycookie != kurabiye null) { ... }”, ASP.Net otomatik olarak adı ile yeni bir çerez oluşturur. “” bu planda ve mycookie eski kurabiye! yazar senin Her zaman kullanın İsteği.Kurabiye Toplama okumak için kurabiyeler!

[ More detail in the article ]

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • CHISTOSITOJAJA

    CHISTOSITOJA

    27 HAZİRAN 2010
  • DJAndrewRyan

    DJAndrewRyan

    22 Ocak 2007
  • PlayStation

    PlayStation

    16 Aralık 2005