简体   繁体   中英

WPF Launch Browser with Credentials

I'm using WPF and C#.

I want to be able to launch a browser window, most likely IE, and provide known credentials so that the Windows-based application can handle the transition from itself to an outside browser without having the user enter his/her credentials again.

I do know how to launch the browser:

System.Diagnostics.Process.Start(url);

My main question is, how can I attach authentication to that? Perhaps by adding headers to it somehow?

Lastly, I don't really want to use the new WebBrowser control inside of WPF due to it's current problems with displaying with a transparent window.

It's going to depend on how the web site handles user authentication. If you own the website, you can create a url that will log the user in with the information you provide.

Nick,

The authentication will be handled in different ways: -

  1. Proxy Authentication is handled by Windows manually.
  2. Forms Based authentication is handled by cookies, so the user needs to have the cookies present.
  3. Windows NTML might be in the 'keychain' on the Operating system (Remember this password).

Cheers,

Phil.

1) You have to know how to "log in". To do this login manually in the web application and trace the http traffic with http debugger like Fiddler. Pay attention what kind of http requests are sent, what names have the parameters, etc. Once you know what sequence of http requests has to be send to log in you has to do this with the browser.

2) Implement log in automatically 2.1) If by any chance log in happens via http GET - just append the right query string to the url and start the browser. This could happen only if you control the web application and build in this mechanism, other wise log in is almost always implemented as POST with https.

2.2) If you have to do POST request you have several options: 2.2.1) You could provide local html document, that contains javascript and make ajax call to the login form from the javascript. To pass the parameters you could use get parameters.

2.2.2) If nothing else works you will have to use the browser via COM (WebBrowser control)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM