Popup and web uri within c# desktop application
-
30-09-2019 - |
Question
I need to access some web api from my desktop application for authentication. For example, facebook api, it requires to redirect to facebook page for allow permission from user and then it redirect back along with an access token which is needed for accessing private data. Now, on facebook documentation they alreasy metioned that, webbrowser class of .NET framework can help in this case. THere are two webbrowser class, one for wpf application, at msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx, another is for windows forms application, at msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx
Now, My question is, how can i use this to make a broser like popup of the url and after it back , retrieve the url again.
Regards
Solution
Well, I will list the steps for you, and it's easier that you may think:
- Create a new
Form
that will be used to house theWebBrowser
control and style it to look like a popup. - Add the WebBrowser to the form - by default, this will fill the entire forms layout
- Use the
Navigate()
method on the WebBrowser to go to the needed URL - Once the user has clicked the button, check the
Url
property on the WebBrowser and get the token (Hint: you can use theNavigated
event to determine when the page is (re)loading.)