Hi Sir,
How can we show reading fetching data after closing and reopening of browser/ tab. using c# asp.net?
Hi Sir,
How can we show reading fetching data after closing and reopening of browser/ tab. using c# asp.net?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Apr 21, 2023, 12:06 AM EDT
In order to persist data between browser sessions in an ASP.NET application, you can use various techniques such as cookies, session state, caching, and local storage. Here are some examples of how you can implement these techniques using C# in ASP.NET:
Cookies: Cookies are small text files that are stored on the user's computer and can be used to store user-specific data. You can use the following code to create a cookie:
HttpCookie cookie = new HttpCookie("myCookie"); cookie.Vaue = "myValue"; cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie);To retrieve the value of the cookie, you can use the following code:
if (Request.Cookies["myCookie"] != null) { string value = Request.Cookies["myCookie"].Value; }Session state: Session state allows you to store data that is specific to a user session. To store data in session state, you can use the following code:
Session["myKey"] = "myValue";To retrieve the value from session state, you can use the following code:
if (Session["myKey"] != null) { string value = Session["myKey"].ToString(); }Caching: Caching allows you to store frequently accessed data in memory for faster access. To cache data, you can use the following code:
Cache.Insert("myKey", "myValue", null, DateTime.Now.AddHours(1), TimeSpan.Zero);To retrieve the value from cache, you can use the following code:
if (Cache["myKey"] != null) { string value = Cache["myKey"].ToString(); }