问题描述:

What I am trying to achieve :

I wanted to interact between console app and Internet explorer. I am initiating a OAuth work flow which take user name and password as input and retrieve call back url with access token and access secret. I am in a position to achieve the same using Web Browser control in Windows Forms which has oauthBrowser_Navigated event trig erred.

What I have tried :

I have tried achieving the result using web browser control in desktop application. I am attaching the logic for reference

 private void oauthBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)

{

if (e.Url.Host == "www.example.com")

{

NameValueCollection query = HttpUtility.ParseQueryString(e.Url.Query);

_oauthVerifier = query["oauth_verifier"];

_ippRealmOAuthProfile.realmId = query["realmId"];

_ippRealmOAuthProfile.dataSource = query["dataSource"];

_caughtCallback = true;

oauthBrowser.Navigate("about:blank");

}

else if (_caughtCallback)

{

IToken accessToken = exchangeRequestTokenForAccessToken(_consumerKey, _consumerSecret, _requestToken);

_ippRealmOAuthProfile.accessToken = accessToken.Token;

_ippRealmOAuthProfile.accessSecret = accessToken.TokenSecret;

_ippRealmOAuthProfile.expirationDateTime = DateTime.Now.AddMonths(6);

this.DialogResult = DialogResult.OK;

this.Close();

}

}

Explanation

Every time navigation take place i.e Navigated event is triggered where you can check the URL property

What I have tried in Console :

 private void WinSys(string url)

{

try

{

var IE = new SHDocVw.InternetExplorer();

object URL = url;

IE.ToolBar = 0;

IE.StatusBar = false;

IE.MenuBar = false;

IE.Width = 622;

IE.Height = 582;

IE.Visible = true;

IE.Navigate2(url, null, null, null, null);

while (IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)

{

if (IE.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)

{

IE.NavigateComplete2 +=IE_NavigateComplete2;

Console.WriteLine("Loaded");

System.Threading.Thread.Sleep(5000);

}

}

}

catch (Exception)

{

throw;

}

}

I am trying to trigger the navigate event when IE changes the URL in a console application. I shouldn't loose my control in console application because it completes the execution and doesn't wait for interaction with Internet explorer navigate event property.

相关阅读:
Top