2011-12-13 19 views
8

Kullanıcı adını çerezde saklamak ve kullanıcı web sitesini açtığında almak istiyorum. Tarayıcı kapalıyken sona ermeyen bir çerez oluşturmak mümkün mü? Web sitesi oluşturmak için asp.net C# kullanıyorum. Ve nasıl daha sonra isterseniz, bir çerez Shai söylediklerine ek olarakDize bir çerezde nasıl saklanır ve getirilir

HttpCookie myCookie = Request.Cookies["MyTestCookie"]; 

// Read the cookie information and display it. 
if (myCookie != null) 
    Response.Write("<p>"+ myCookie.Name + "<p>"+ myCookie.Value); 
else 
    Response.Write("not found"); 
+0

bu kontrol edin: aynı çerez kullanımını güncellemek 210 http://stackoverflow.com/questions/8485186/how-to-set-remember-me-in-login-page-without-using-membeship-in-mvc-2-0/8485215#8485215 –

cevap

22

kurtarmaya sunan tarayıcı durdurabilir

HttpCookie myCookie = Request.Cookies["MyTestCookie"]; 
DateTime now = DateTime.Now; 

// Set the cookie value. 
myCookie.Value = now.ToString(); 

// Don't forget to reset the Expires property! 
myCookie.Expires = now.AddYears(50); 
Response.SetCookie(myCookie); 
+0

Ekle Referans @Shai https://msdn.microsoft.com/en-us/library/aa287547(v=vs.71).aspx – Danilo

2

Okuma bir çerez

HttpCookie myCookie = new HttpCookie("MyTestCookie"); 
DateTime now = DateTime.Now; 

// Set the cookie value. 
myCookie.Value = now.ToString(); 
// Set the cookie expiration date. 
myCookie.Expires = now.AddYears(50); // For a cookie to effectively never expire 

// Add the cookie. 
Response.Cookies.Add(myCookie); 

Response.Write("<p> The cookie has been written."); 

Yazma kullanıcı adını ve şifresini

+0

Bu, bir cevap yerine yorum yapmak için daha uygun olabilir. – Kmeixner

İlgili konular