Click here to Skip to main content
Rate this: bad
good
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 17: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 at 2-Jan-13 23:18pm
   
+5
_Amy at 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
0 DamithSL 320
1 OriginalGriff 155
2 Peter Leow 115
3 Afzaal Ahmad Zeeshan 114
4 deepakdynamite 110
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 4,994
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
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