There is a task: There is a main WPF application that runs several (different number) copies of another WPF application. Each copy contains a component WebBrowser, on which authorization is performed on the website http://n.site/ Each copy must have its own cookie area, since each copy authorizes 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" we need to run copies in different domains.
Question: how to do this?
P.S. the main application and copies use the same external dll, if that matters.
P.S.S I already implemented this in WinForms, and there the space for cookies was different for app copies without changing the domain.
I will be grateful for any help!
I found a solution! To change this behavior, you need to change the WinINET settings using the InternetSetOption function. To prevent using common cookies by running copies of the same application, you must change the WinINET settings when you start 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");
}