我在C#中创建了一个Web浏览器,并使用此代码清除cookie。
但我收到错误..
private void button1_Click(object sender, EventArgs e)
{
if (Request.Cookies["UserSettings"] != null)
{
HttpCookie myCookie = new HttpCookie("UserSettings");
myCookie.Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Add(myCookie);
}
}
错误
错误2类型或命名空间名称' HttpCookie'找不到(你错过了使用指令或汇编引用吗?)c:\ users \ supun \ documents \ visual studio 2013 \ Projects \ FACEBOOK GROUP海报\ FACEBOOK GROUP海报\ Form1.cs 35 17 FACEBOOK GROUP海报
错误4名称'回复'在当前上下文中不存在c:\ users \ supun \ documents \ visual studio 2013 \ Projects \ FACEBOOK GROUP POSTER \ FACEBOOK GROUP POSTER \ Form1.cs 37 17 FACEBOOK GROUP海报
你有任何想法解决这个问题吗?
答案 0 :(得分:1)
删除Cookie不是那么简单。看看这个post:
您需要导入:
[System.Runtime.InteropServices.DllImport("wininet.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetOption(int hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
然后,使用以下方法调用InternetSetOption:
int option = (int)3/* INTERNET_SUPPRESS_COOKIE_PERSIST*/;
int* optionPtr = &option;
bool success = InternetSetOption(0, 81/*INTERNET_OPTION_SUPPRESS_BEHAVIOR*/, new IntPtr(optionPtr), sizeof(int));
if (!success)
{
MessageBox.Show("Encountered an error");
}
您可能需要在“属性”下指定您的程序集不安全 - >构建标签。