當(dāng)前位置:
首頁(yè) >
使.NET WebBrowser不与IE或其他实例共享cookie
發(fā)布時(shí)間:2024/9/20
44
豆豆
生活随笔
收集整理的這篇文章主要介紹了
使.NET WebBrowser不与IE或其他实例共享cookie
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
由于C#中的WebBrowser與包括IE在內(nèi)的所有其他WebBrowsers實(shí)例共享cookie,我希望WebBrowser擁有自己的cookie容器,該容器不共享之前在IE或其他實(shí)例中創(chuàng)建的任何cookie。
因此,例如,當(dāng)我創(chuàng)建WebBrowser時(shí),它不應(yīng)該有任何cookie。 當(dāng)我運(yùn)行2個(gè)WebBrowsers實(shí)例時(shí),它們擁有自己的cookie容器,并且不會(huì)彼此共享或沖突cookie。
我怎樣才能做到這一點(diǎn)?
您可以使用InternetSetOption?Win32函數(shù)執(zhí)行此過(guò)程:
[DllImport("wininet.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)] public static extern bool InternetSetOption(int hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);然后在您的應(yīng)用程序啟動(dòng)時(shí)調(diào)用以下函數(shù):
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位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的使.NET WebBrowser不与IE或其他实例共享cookie的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: sae10w30CC是什么机油与20W5
- 下一篇: 悲哀的VB.Net