leontager Posted August 6, 2003 Posted August 6, 2003 how can I clear the cookies from internet explorer. is there any built in function or do I have to scan for each file? if so, could you please provide me with sample code. If possible please make it as simple as possible since I am new:D Quote
aewarnick Posted August 12, 2003 Posted August 12, 2003 Cookies are just text files stored in windows in the Cookies folder. Just delete them. Quote C#
Leaders dynamic_sysop Posted August 12, 2003 Leaders Posted August 12, 2003 this should do the job ... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cookiePath() As String = Directory.GetFiles("C:\Documents and Settings\den\Cookies") '/// path to your cookies folder must go here. Dim x As Integer For x = LBound(cookiePath) To UBound(cookiePath) If cookiePath(x).Substring(cookiePath(x).Length - 4, 4) = ".txt" Then File.Delete(cookiePath(x)) End If Next End Sub hope it helps :) Quote
*Experts* mutant Posted August 12, 2003 *Experts* Posted August 12, 2003 If you dont want to hardcode the cookie path, since it can be different on other computer you can use this to retrieve the path to the cookies folder: System.Environment.SpecialFolder.Cookies :) Quote
Leaders dynamic_sysop Posted August 12, 2003 Leaders Posted August 12, 2003 although when i used System.Environment.SpecialFolder.Cookies i got an error, path not found ( pointing to the app's path / bin ) , thats why i pointed to the actuall name. not sure whats going on there. Quote
*Experts* mutant Posted August 12, 2003 *Experts* Posted August 12, 2003 This is how you use it: Dim files() as string = IO.Directory.GetFiles(System.Environment.GetFolderPath(Environment.SpecialFolder.Cookies)) You need to use the GetFolderPath() method becuase SpecialFolder is just an enumaration. :) Quote
leontager Posted August 13, 2003 Author Posted August 13, 2003 i've done it abit differently. I should have posted earlier. I did something similar to waht dynamic_sysop suggested. im f As IO.FileInfo Dim dir As New IO.DirectoryInfo("C:\Documents and Settings\user1\Cookies\") For Each f In dir.GetFiles If f.Extension = ".txt" Then IO.File.Delete(f.FullName) End If Next I will change it to what you added mutant. Thanx everybodys replys. I appriciate it very much :-) Quote
aewarnick Posted August 16, 2003 Posted August 16, 2003 The problem with doing it that way is that it is not compatable with win98. Quote C#
Eduardo Lorenzo Posted December 8, 2006 Posted December 8, 2006 Dim f As IO.FileInfo Dim dir As New IO.DirectoryInfo("C:\Documents and Settings\user1\Cookies\") For Each f In dir.GetFiles If f.Extension = ".txt" Then IO.File.Delete(f.FullName) End If Next will this happen on the Client side? or on the Server? I mean.. will this delete the cookies on the client machine? Quote
MrPaul Posted December 9, 2006 Posted December 9, 2006 Request.Cookies.Clear() If a website were able to remotely delete all of a client's cookies this sounds like a bit of a security flaw, and even if it is possible I would advise against it. You can delete all of a client's cookies for the current site by using the Request.Cookies collection. You can also use this collection to add, modify, inspect and delete individual cookies. Request.Cookies.Clear() 'Clear all cookies Good luck :) Quote Never trouble another for what you can do for yourself.
Eduardo Lorenzo Posted December 11, 2006 Posted December 11, 2006 If a website were able to remotely delete all of a client's cookies this sounds like a bit of a security flaw' date=' and even if it is possible I would advise against it. You can delete all of a client's cookies [i']for the current site[/i] by using the Request.Cookies collection. You can also use this collection to add, modify, inspect and delete individual cookies. Request.Cookies.Clear() 'Clear all cookies Good luck :) this will delete only MY cookies on the CLient Side? I mean, I want my website to be able to display something like "All cookies cleared." message which of course would mean all the cookies that I save on the client's computer has been deleted. Quote
MrPaul Posted December 11, 2006 Posted December 11, 2006 Cookie deletion... Apologies, I replied without really thinking. The code above will clear the Cookies collection and so prevent any further cookies from being set on the client. It will not affect cookies already on the client. To do that, each cookie's expiration time must be modified: For i As Integer = Request.Cookies.Count - 1 To 0 Step -1 Dim c As New HttpCookie(Request.Cookies(i).Name) c.Expires = DateTime.Now.AddDays(-1D) Request.Cookies.Add(c) Next Or for (int i = Request.Cookies.Count - 1; i >= 0; i--) { HttpCookie c = new HttpCookie(Request.Cookies[i].Name) c.Expires = DateTime.Now.AddDays(-1d) Request.Cookies.Add(c) } Good luck :) Quote Never trouble another for what you can do for yourself.
Eduardo Lorenzo Posted December 11, 2006 Posted December 11, 2006 Thank you very much MrPaul.. But what if I want to delete the cookies when a certain event is triggered? I have this: function resetStatus() { var abssize = document.body.offsetWidth-30; if((event.clientY < 0 && event.clientX >= abssize) || (event.clientY < 0 && event.clientX >= 0)) { alert("The page will now close."); window.open("../forceLogout.asp", "_blank"); } } and forcelogout.asp does a bit of "garbage collection" which SHOULD include the deletion of cookies because I have to force a logout because the user closed the browser "ilelgally" by not clicking my "logout" link. Quote
MrPaul Posted December 11, 2006 Posted December 11, 2006 Code in forceLogout.aspx If the user closes their browser window, all non-persistent cookies are automatically deleted, as they are assigned to a specific browser window. If you want to delete persistent cookies, then you would put the code from my previous post into forceLogout.aspx. It may be possible to delete cookies using client-side Javascript, but it is certainly not the standard approach. :) Quote Never trouble another for what you can do for yourself.
Eduardo Lorenzo Posted December 11, 2006 Posted December 11, 2006 guess what.. I got clearance from the admin to delete ALL cookies in all terminals.. :D (someone jsut handed me a mallet!) it seems developers here have had problems with cookies and trapping the X button click for quite some time.. thank you very much MrPaul and im happy you liked my forcelogout code. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.