C#消除WebBrowser中Cookie緩存的辦法。本站提示廣大學習愛好者:(C#消除WebBrowser中Cookie緩存的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#消除WebBrowser中Cookie緩存的辦法正文
本文實例講述了C#消除WebBrowser中Cookie緩存的辦法。分享給年夜家供年夜家參考,詳細以下:
比來用C#寫一個法式,用一個窗體中的WebBrowser來上岸網站,然則WebBrowser有cookie緩存,第二次上岸的時刻WebBrowser依然是第一次上岸後的狀況,所以要消除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#法式設計有所贊助。