使.NET WebBrowser不与IE或其他实例共享cookie
生活随笔
收集整理的這篇文章主要介紹了
使.NET WebBrowser不与IE或其他实例共享cookie
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
由于C#中的WebBrowser與包括IE在內的所有其他WebBrowsers實例共享cookie,我希望WebBrowser擁有自己的cookie容器,該容器不共享之前在IE或其他實例中創建的任何cookie。
因此,例如,當我創建WebBrowser時,它不應該有任何cookie。 當我運行2個WebBrowsers實例時,它們擁有自己的cookie容器,并且不會彼此共享或沖突cookie。
我怎樣才能做到這一點?
您可以使用InternetSetOption?Win32函數執行此過程:
[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 !>?"); } } 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的使.NET WebBrowser不与IE或其他实例共享cookie的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sae10w30CC是什么机油与20W5
- 下一篇: 正新的轮胎怎么样 评测正新轮胎的性能和质