views:

43

answers:

2

I am using WebBrowser Control in the WinForms application (C#). I want to write program which can put Login and Password for some user and test some functionality. It's working fine when I am running one Application instance, but I have problem when I am trying to run two app copies with different users - both instances are working with the same user and it's impossible to log in with different users. For example, I want to log-in to the same web site as User1 in one application and as User2 in the other app instance and perform tests.

How it's possible to implement program to allow two different app instances with WebBrowser Control to work with different users? As I understand, I have to isolate cookies somehow so different application instances will use their own sessions.

A: 

Do you understand why this is happening? You can't really "isolate the two cookies", but you could redo the app to use some sort of session key instead and POST values. It's creating a cookie using the IE settings, so it's putting the cookie in the default location.

I suppose you could override that functionality, but you would probably have to override WebBrowser.

drachenstern
Thank for advice, do you know where can I read something about session keys, because I am not really familiar with cookies. Any idea how this can be done is really useful.
ArmHorse
Hmmm, cookies are kind of fundamental to web programming, they're not really an "add-on"... here's two resources: http://www.w3schools.com/asp/asp_cookies.asp http://en.wikipedia.org/wiki/HTTP_cookie but I don't know that those will help you. I'm going to guess that you don't understand what the problem is. SO is not really the best way to help you on this. Is there anyone locally you can ask to help you with this? I don't mind walking you through it, but I'm sure a whiteboard or something will be much handier in the explanation...
drachenstern
Turn off 'auto logon with NT credentials' in your internet settings. That should pop up the 'login' dialog for both browserControls when they browse to your server location. This should get you into 'multi security context' mode and get you started.
Marvin Smit
@Marvin, No I don't think it will work, because that's not what's happening. He's initiating two sessions and it's not asking him to set a second user. It's using the stored cookie of the first user. ~~ Additionally, that configuration only works with intranet sites. So if this is found to be the problem, then it may become a deployment issue. This setting is the default for IE.
drachenstern
Thank you for links, so as I understand so far - Cookies are like a simple key/value pairs, and IE uses same pair for given web-site for any WebBrowser instance. I see that WebBrowser has property with Cookies so this provides simplest idea (not sure if it will work) - just change Cookies for the second WebBrowser instance to use login/pass for second user. But I am not sure if this even possible.BTW. I will ask around about someone with good experience with WinForms WebBrowser and cookies, but I am not sure that I will find someone :)
ArmHorse
You're mostly correct, except the setting of the cookie is a function of the WebBrowser, so I don't think you can override that. Yes cookies are like simple keypairs, and they are transmitted to the server on every retrieval of information (so generally you should keep them as small as possible). Wish I could give you more direction on this, but it sounds like we're going to have fundamental design differences as you go forward. I would personally focus on building a web portal based on ASP.NET instead of worrying about the desktop app used to access the site. Just me tho.
drachenstern
A: 

I don't think this is an issue with your app as much as it is with how the website is functioning. Creating a cookie is a function of the browser and the website, not your client app. Do you have the ability to change the website code?

Nathan Loding
No, I am not able to change web site code
ArmHorse