I want tp build a WPF (or Windows Forms if it can solve the problem) that can display simultaneously the same web page with different credentials (it’s testing tool for a web application with complex user action flow).
I have, by now, a very simple WPF app :
<Window x:Class="TestTool.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<WebBrowser Margin="8" Source="http://theapptotest" />
<WebBrowser Margin="8" Source="http://theapptotest" Grid.Column="1" />
</Grid>
</Window>
This is not the target layout of the application, but it will allows to test if my goal is possible.
The application, as expected, display side by side the same web app. However, if I log in in the first web brower control, the second is logged in too. I guess it’s because the cookies are shared for the current user.
I checked into the WebBrowser class documentation but I did not find anything useful.
How can I reach my goal?
Is it possible to “isolate” one webbrowser from the others?
Is it possible to “impersonate” a user control? Like some applications (web browser mostly) are spawning different processes, can I “spawn” processes under a different account and display it in my main window ?
Please note that I don’t have to interact with the web pages. I just want to able to switch user by changing a tab of my application (one tab per user).
PS: I’m not stick to Internet Explorer engine, if a solution exists with alternatives browsers, let me know
PS: the target application use two authentication mechanisms. A user can authenticate with Windows account, or a custom Form based authentication. if required, I can use only forms authentication (a separate cookie container would do the job, if I can plug it).
[Edit] I’ve tried to spawn with other users credentials new instances of Internet Explorer, then attach the process main window by settings its parent to one of my windows form host. This is however, very unreliable (process often crash, can’t work if any existing instance of IE is running, etc.
Ok, I finally found a way to reach my goal, with the help of Simon Mourrier previous answer.
I’ve created a custom user control:
Xaml part:
With this code behind :
I have to cheat a bit :
-noframemergingwhen firingIExplore.exein order to avoid internal IE session sharing.MainWindowHandleproperty change after some few milliseconds (I guess iexplore has a bootstrapper process to either connect to existing process or spawn a new one, with new handle, or something like this).I still have to extend the user control to accept input parameters (url is hardcoded), but the idea is here. I just have to concentrate on the app itself.