C # Removal of cookies Code _c# tutorial

Source: Internet
Author: User

Different browsers store cookie files in different places

The following is the storage path for C # WebBrowser control cookies

c:\users\{your account name}\appdata\local\microsoft\windows\inetcookies.

Cookies file format Please check the relevant information

Here is the code to clear cookies:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.IO;
Namespace Delcookies
{
class program
{
static void Main (string[] args)
{
delcookies (" 360.cn/");
Console.WriteLine ("Cookies have been removed.");
Console.read ();
}
static void Delcookies (string domain)//domain is the domain where the cookies belong, this method is to remove cookies by filtering the owning domain
{
//Get file path string in directory
[] cookies = Directory.GetFiles (Environment.getfolderpath (Environment.SpecialFolder.Cookies));
foreach (string file in cookies)
{
try
{
StreamReader sr = new StreamReader (file);
String txt = Sr. ReadToEnd ();
Sr. Close ();
if (txt. IndexOf (domain)!=-1)//judge whether to delete the cookies file
{
file.delete (file)
;
}
catch (Exception ex)
{
}
}
}}

About C # to remove cookies code for everyone to write so much, I hope to help you, if you have any questions welcome to my message, small series will promptly reply to everyone!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.