There is such a task: There is a basic WPF application that runs several (different number) copies of another WPF application. Each such copy contains a WebBrowser component, on which authorization is performed on the website http://n.site/ Each such copy must have its own cookie area, since each copy is authorized by different accounts. As you know, the WebBrowser component uses the “one cookie space” for all launched components. I read that in order to divide this "space" you need to run copies in different domains.

Question: how to implement it? PS the main application and copies use the same external dll, if that matters. Thank you in advance. PSS I already implemented similar in WinForms, and there the space of cookies was different for cookies without changing the domain.

    1 answer 1

    To change this behavior, you must change the WinINET settings using the InternetSetOption function. To prevent WebBrowser from running copies of the same general cookie application, you must change the WinINET settings when you run each copy using the following function.

    [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern bool InternetSetOption(int hInternet, int dwOption, ref int option, int dwBufferLength); public static void SuppressCommonCookieBehaviour() { /* 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 = 3; /* INTERNET_SUPPRESS_COOKIE_PERSIST */ bool success = InternetSetOption(0, 81 /* INTERNET_OPTION_SUPPRESS_BEHAVIOR */ , ref option, sizeof(int)); if (!success) throw new InvalidOperationException("InternetSetOption() returns false"); }