How can I delete a specific cookie from within my application? Everywhere I look for this turns up being for web development.
Cookies ARE for the web to detect info off any box. So, what is your exact objective....if it is deletion all you need is JavaScript to which you have to pass the cookie name to delete.
If this doesn't answer your question...please elaborate your context.
EDIT Ok, see if this helps use WebBrowser control available in Winforms
You can find cookies on the filesystem (for IE) in here:
C:\Documents and Settings\[User]\Local Settings\Temporary Internet Files
Having a quick mess around in .NET 2008 you might be able to do something using the System.Web Library.
I took the example at the bottom of the page found in the MSDN Here and took out the errors so that they referenced the Response and Request objects (HttpRequest and HttpResponse).
This is not tested and i doubt it will even do its job, but it might help point you in the right direction. Also, i dont think this sort of think can be done... but maybe there is a way you can access the cookie collection.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
HttpRequest Request = null;
HttpResponse Response = null;
String output;
StringBuilder sb = new StringBuilder();
// Get cookie from the current request.
HttpCookie cookie = Request.Cookies.Get("DateCookieExample");
// Check if cookie exists in the current request.
if (cookie == null)
{
sb.Append("Cookie was not received from the client. ");
sb.Append("Creating cookie to add to the response. <br/>");
// Create cookie.
cookie = new HttpCookie("DateCookieExample");
// Set value of cookie to current date time.
cookie.Value = DateTime.Now.ToString();
// Set cookie to expire in 10 minutes.
cookie.Expires = DateTime.Now.AddMinutes(10d);
// Insert the cookie in the current HttpResponse.
Response.Cookies.Add(cookie);
}
else
{
sb.Append("Cookie retrieved from client. <br/>");
sb.Append("Cookie Name: " + cookie.Name + "<br/>");
sb.Append("Cookie Value: " + cookie.Value + "<br/>");
sb.Append("Cookie Expiration Date: " +
cookie.Expires.ToString() + "<br/>");
}
output = sb.ToString();
}
}
}