C# 如何从按钮清除web浏览器的Cookie

C# 如何从按钮清除web浏览器的Cookie,c#,cookies,C#,Cookies,我用C语言创建了一个web浏览器,并使用此代码清除cookie 但是我有一些错误 private void button1_Click(object sender, EventArgs e) { if (Request.Cookies["UserSettings"] != null) { HttpCookie myCookie = new HttpCookie("UserSettings"); myCooki

我用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”是否缺少using指令或程序集引用?c:\users\supun\documents\visualstudio 2013\Projects\FACEBOOK GROUP POSTER\FACEBOOK GROUP POSTER\Form1.cs 35 17 FACEBOOK GROUP POSTER

错误4当前上下文c:\users\supun\documents\visual studio 2013\Projects\FACEBOOK GROUP POSTER\FACEBOOK GROUP POSTER\Form1.cs 37 17 FACEBOOK GROUP POSTER中不存在名称“Response”


你有什么办法解决这个问题吗?

删除cookies并不是那么简单。看看这个:

您需要导入:

[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");
}

您可能必须在“属性->生成”选项卡下将程序集标记为不安全。

您的代码顶部是否有对System.Web的引用,即使用System.Web;?在不了解代码的位置以及这是ASP.NET还是其他内容的情况下,不确定第二个代码。不,我没有使用system.web。我想在c窗体appWell上添加这些按钮。这是你的问题,你不能只是把一堆web库放到一个窗体中,然后期望它们神奇地工作。。。