C#清除WebBrowser中Cookie緩存的方法
本文實例講述了C#清除WebBrowser中Cookie緩存的方法。分享給大家供大家參考,具體如下:
最近用C#寫一個程序,用一個窗體中的WebBrowser來登陸網(wǎng)站,但是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 !>?"); } }
更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#常見控件用法教程》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計入門教程》及《C#程序設(shè)計之線程使用技巧總結(jié)》
希望本文所述對大家C#程序設(shè)計有所幫助。
相關(guān)文章
C#調(diào)用sql2000存儲過程方法小結(jié)
這篇文章主要介紹了C#調(diào)用sql2000存儲過程的方法,以實例形式分別對調(diào)用帶輸入?yún)?shù)及輸出參數(shù)的存儲過程進行了詳細分析,非常具有實用價值,需要的朋友可以參考下2014-10-10Unity UGUI的ScrollRect滾動視圖組件使用詳解
這篇文章主要為大家介紹了Unity UGUI的ScrollRect滾動視圖組件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07C#寫入對象或集合類型數(shù)據(jù)到xml文件的方法
這篇文章主要介紹了C#寫入對象或集合類型數(shù)據(jù)到xml文件的方法,涉及C#針對XML文件的相關(guān)操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07