Click here to Skip to main content
12,455,701 members (93,697 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
How to delete cache,cookie,hiddenfield in asp.net using C# please provide some examples to how to implement it???
Posted 2-Jan-13 16:25pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Here you go..
Deleting Cache:
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetNoStore();
Response.Expires = -1500;
Deleting Cookie:
cookie.Expires = DateTime.Now.AddYears( -30 );
context.Response.Cookies.Add( cookie );
Deleting HiddenField:
HiddenField.Delete()
//Sorry, just kidding here
You cannot delete the HiddenField. Rather you can set the value of the HiddenField as empty.
HiddenField.Value = "";


--Amit
  Permalink  
Comments
Abhishek Pant 2-Jan-13 23:18pm
   
+5
_Amy 2-Jan-13 23:19pm
   
Thanks Abhishek. :)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

hi,

// During the time of Cookie Creation Set its expiration time.
       HttpCookie cookie=new HttpCookie("test");
       // Cookie expire after 1 day
       cookie.Expires = DateTime.Now.AddDays(1);
       // Add Cookie
       Response.Cookies.Add(cookie);
 
       // you cann't delete hidden field.
       // Set value of hidden  field to blank
       hdnData.Value = "";
 
       // For Cache Expiration
       Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
       Response.Cache.SetCacheability(HttpCacheability.Public);
       Response.Cache.SetValidUntilExpires(true);

Check this link for cache expiration :
http://msdn.microsoft.com/en-us/library/y18he7cw(v=vs.100).aspx[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100