Set IE cookie to go

Source: Internet
Author: User

C # set IE Cookie to automatically open the need to login to the page, such as the QQ panel on the QQ space, he directly into your QQ zone, no need to log in again. This is actually the use of an API function is done, but the setting is very skillful.

///
Set cookies
///

[DllImport ("Wininet.dll", CharSet = CharSet.Auto, SetLastError = True)]
public static extern bool InternetSetCookie (string lpszurlname, String lbszcookiename, string lpszcookiedata);
///
Get cookies
///

[DllImport ("Wininet.dll", CharSet = CharSet.Auto, SetLastError = True)]
public static extern bool InternetGetCookie (
String URL, string name, StringBuilder data, ref int datasize);
static void Main (string[] args)
{
Get the old
StringBuilder cookie = new StringBuilder (New String (', 2048));
int datasize = cookie. Length;
BOOL b= InternetGetCookie ("http://community.csdn.net", null, cookie, ref datasize);
Delete the old
foreach (String fileName in System.IO.Directory.GetFiles (System.Environment.GetFolderPath ( Environment.SpecialFolder.Cookies)))
{
if (Filename.tolower (). IndexOf ("csdn") > 0)
{
System.IO.File.Delete ("Csdn");
}
}
Generate a new
foreach (string C in cookie. ToString (). Split (';'))
{
string[] Item = c.split (' = ');
String name = Item[0];
String value = Item[1] + "; expires=sun,22-feb-2099 00:00:00 GMT";
InternetSetCookie ("Http://community.csdn.net", Name,value);
InternetSetCookie ("Http://forum.csdn.net", name, value);
InternetSetCookie ("Http://webim.csdn.net", name, value);
}
}

Set the cookie information through the code above, save it to the Temp folder, and

A word.
System.Diagnostics.Process.Start ("IEXPLORE. EXE "," webim.csdn.net ");//Invoke IE to open web page

OK will return directly to the successful login page.

Set IE cookie to go

Related Article

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.