有一个任务:有一个主WPF应用程序运行另一个WPF应用程序的几个(不同数量)副本。每个副本都包含一个组件WebBrowser,在网站上执行授权http://n.site/每个副本都必须有自己的cookie区域,因为每个副本都授权不同的帐户。如您所知,WebBrowser组件对所有已启动的组件使用“一个cookie空间”。我读到,为了划分这个“空间”,我们需要在不同的域中运行副本。
问题:怎么做?
附:主要应用程序和副本使用相同的外部DLL,如果这很重要。
P.S.S我已经在WinForms中实现了这一点,并且在不更改域的情况下,应用程序副本的cookie空间不同。
我将不胜感激任何帮助!
我找到了解决方案!若要更改此行为,您需要使用InternetSetOption函数更改WinINET设置。要通过运行同一应用程序的副本来防止使用常见cookie,必须在使用以下函数启动每个副本时更改WinINET设置。
[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");
}