on the client side, use document.cookie, see GetCookie() function in the sample code on this URL:http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/cookie.asp
what I said is applicable to the webform, if you are programming winform, you have to read the cookie file yourself, or use some win32 API, see how people try to delete the cookies:http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20493107.html
据说用api InternetGetCookie 可以轻松搞定,但是总在C#中没有调用成功,请高手指点:[DllImport("wininet.dll")] public static extern bool InternetGetCookie( string lpszUrlName, string lpszCookieName, out string lpszCookieData, long dwszie ); #endregion
public static extern bool InternetGetCookie(
string lpszUrlName,
string lpszCookieName,
out string lpszCookieData,
long dwszie
);
#endregion
public static string GetCookie(string url){
string sb;
InternetGetCookie(url,"",out sb,256);
return sb;
}
using System;
using System.Text;
using System.Runtime.InteropServices;
class TestCookie
{ [DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool InternetGetCookie(
string lpszUrlName,
string lpszCookieName,
StringBuilder lpszCookieData,
ref uint lpdwSize
);
[DllImport("kernel32.dll")]
internal static extern Int32 GetLastError(); public static string GetCookie(string url)
{
StringBuilder sb = new StringBuilder(1000);
uint size = 1000;
bool bGood = InternetGetCookie(url,"", sb,ref size);
if (!bGood)
Console.WriteLine("Error code:{0}", GetLastError()); return sb.ToString();
}
public static void Main()
{
Console.WriteLine(GetCookie("http://expert.csdn.net"));
}
}