10

I would like to create a .NET application that utilizes multiple instances of the WebBrowser control. The catch is that I'd like each web browser control to be running it's own session. IOW, I have a requirement that the collection of session cookies, javascript global namespace, etc. is separate for each instance and that all instances appear within the same window.

AFAIK, this is going to require me to run each web browser control in a separate process.

A few questions:

  1. Is my assumption about multiple processes being required correct?
  2. Is it possible to cause each WebBrowser instance in a single Windows Forms app to run in a separate process?

Thanks in advance...

Justin Voshell
  • 175
  • 1
  • 8
  • Hello, I see this is answered, but how did you manage? I created to VB6 (in my case) applications that use the WebBrowser component and they still share the same session. Dunno if I should post another question.. – Vlagged Oct 21 '09 at 16:45

2 Answers2

9

Currently, no, you cannot implement isolation of this sort using the Web Browser control without putting each instance in a different process.

You could run each control in an out-of-process COM server or a new instance of your application, if appropriate.

EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • I'm having same OP need, but no solution in my pocket. I tried putting some `WebBrowser` control in my form: they share same session, I know (it's sad, but I know). Problem is even running multiple instances of my app, they still share same session: I think this is because Internet Explorer process is still the same. Do you have some advice? Thanks – Marco Nov 08 '12 at 11:01
  • 2
    Web Browser Controls' sessions are isolated by process; if you're seeing some sort of "sharing" that means that there's a persistent (non-session) cookie. – EricLaw Apr 04 '14 at 21:35
  • If the IE process can be started with `iexplore.exe -private -nomerge` cookies might be able to be in isolation mode. – Sen Jacob Oct 09 '18 at 09:34
2

It is possible to do that if you can access the hosts file ([Windows]/system32/drivers/etc/hosts).

Just put something like this into the hosts file:

127.0.0.1 web1
127.0.0.1 web2
127.0.0.2 web3
...

(replace the ip address with your server ip) and then you can point your multiple instances of WebBrowser to e.g. http://web1/.., etc. Each instance of the WebBrowser will run a separate session. It works fine. The disadvantage is that you need to (programmaticaly) manage hosts file, which could be a security problem as well.

sth
  • 222,467
  • 53
  • 283
  • 367