2013-08-12 5 views
5

C#의 WebBrowser가 IE를 포함한 WebBrowsers의 다른 모든 인스턴스와 쿠키를 공유하기 때문에 WebBrowser가 쿠키를 공유하지 않는 자체 쿠키 컨테이너를 갖고 싶습니다. 이전에 IE 또는 다른 인스턴스에서 생성되었습니다..NET WebBrowser가 IE 또는 다른 인스턴스와 쿠키를 공유하지 못하도록합니다.

예를 들어 웹 브라우저를 만들 때 쿠키가 없어야합니다. 그리고 WebBrowsers 인스턴스를 두 개 실행하면 자체 쿠키 컨테이너가 있고 서로 쿠키를 공유하거나 충돌하지 않습니다.

어떻게하면됩니까?

답변

3

당신은 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 !>?"); 
    } 
} 
+0

는 스레드 당이 작업을 수행하는 것이 가능을? – EBAG

+0

나는 그렇게 생각하지 않는다. 결국 당신이 사용하는 WebBrowser 컨트롤이 Internet Explorer를 나타내는 네이티브 COM 개체에 대한 래퍼 일뿐이라는 것을 잊지 마십시오. –

+0

쿠키 공유에 관해서는 스레드 단위로도 가능하다고 생각하지 않습니다. 이 세션은 WebBrowser 인스턴스의 프로세스별로 공유됩니다. 다음은 비슷한 [질문]입니다 (http://stackoverflow.com/questions/18055734/net-webbrowser-control-and-dispose/18057266#18057266). – Noseratio