C#清除WebBrowser中Cookie緩存的方法
更新時間:2016年05月17日 11:45:57 作者:Demon
這篇文章主要介紹了C#清除WebBrowser中Cookie緩存的方法,涉及C#針對WebBrowser控件的操作技巧,非常簡單實用,需要的朋友可以參考下
本文實例講述了C#清除WebBrowser中Cookie緩存的方法。分享給大家供大家參考,具體如下:
最近用C#寫一個程序,用一個窗體中的WebBrowser來登陸網站,但是WebBrowser有cookie緩存,第二次登陸的時候WebBrowser仍然是第一次登陸后的狀態(tài),所以要清除WebBrowser的cookie緩存。
在stackoverflow上找到一段可用的代碼:
[DllImport("wininet.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)] public static extern bool InternetSetOption(int hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength); private unsafe void SuppressWininetBehavior() { /* SOURCE: http://msdn.microsoft.com/en-us/library/windows/desktop/aa385328%28v=vs.85%29.aspx * INTERNET_OPTION_SUPPRESS_BEHAVIOR (81): * A general purpose option that is used to suppress behaviors on a process-wide basis. * The lpBuffer parameter of the function must be a pointer to a DWORD containing the specific behavior to suppress. * This option cannot be queried with InternetQueryOption. * * INTERNET_SUPPRESS_COOKIE_PERSIST (3): * Suppresses the persistence of cookies, even if the server has specified them as persistent. * Version: Requires Internet Explorer 8.0 or later. */ 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("Something went wrong !>?"); } }
更多關于C#相關內容感興趣的讀者可查看本站專題:《C#常見控件用法教程》、《C#數據結構與算法教程》、《C#面向對象程序設計入門教程》及《C#程序設計之線程使用技巧總結》
希望本文所述對大家C#程序設計有所幫助。
相關文章
Unity UGUI的ScrollRect滾動視圖組件使用詳解
這篇文章主要為大家介紹了Unity UGUI的ScrollRect滾動視圖組件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07