`

c# webbrowser清空session和清空cookie

    博客分类:
  • C#
阅读更多
//清除Session所需要调用的函数
[ DllImport ("wininet.dll" , SetLastError = true )]
private static extern bool InternetSetOption ( IntPtr hInternet , int dwOption, IntPtr lpBuffer , int lpdwBufferLength );
//清空session
public void ResetSession()
{
    //Session的选项ID为42
    InternetSetOption ( IntPtr.Zero , 42 , IntPtr.Zero , 0 );
}
//清空cookie
public void ResetCookie()
{
    if (c_web.Document != null )
    {
    c_web.Document.Cookie.Remove (0 , c_web.Document.Cookie.Count() - 1 );

    }
    string [] theCookies = System.IO.Directory.GetFiles ( Environment.GetFolderPath (Environment.SpecialFolder.Cookies ));
    foreach (string currentFile in theCookies )
    {
        try
        {
            System.IO.File.Delete (currentFile );
        }
        catch (Exception ex)
        {
        }
    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics