Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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
  • Leaders
Posted

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 :)

  • *Experts*
Posted

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

:)

  • Leaders
Posted
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.

  • *Experts*
Posted

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.

:)

Posted

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 :-)

  • 3 years later...
Posted

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?

Posted

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 :)

Never trouble another for what you can do for yourself.
Posted
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.

Posted

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 :)

Never trouble another for what you can do for yourself.
Posted

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.

Posted

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.

 

:)

Never trouble another for what you can do for yourself.
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...