简体   繁体   中英

How do I get input from the keyboard while debugging a Visual Studio 2010 MVC C# program?

Good morning, Guys!

Here's the context:

I am putting together an OAuth-handling program and I'm almost ready to make the call as described in step E of the OAuth Authentication Flow 1.0a diagram here: https://wiki.fitbit.com/display/API/OAuth+Authentication+in+the+Fitbit+API#OAuthAuthenticationintheFitbitAPI-TheOAuthFlow

The problem is all of the testing is taking place on a local machine, and step D of the flow returns a token and a verifier. I am not able to get access to those items in my code because there doesn't seem to be a URL shortener service that will work correctly with multiple returning parameters (neither goo.gl nor http://para.ms/index.php do the trick).

However, using Fiddler, I am able to view the token and the verifier... just not able to get access to them from my oauth callback method, as the parameters are stripped away by the URL shortener services.

I got the idea to copy and paste those items into my code (via some sort of console input such as Console.ReadLine) while it is running in debugger, and continue processing step E with the manually input values. However, I cannot seem to find a way to actually input the values into my code as it is running. The debugger merrily proceeds past the ReadLine command and the values remain null.

I looked at How to make Visual C# studio recognize key input and several other google results which all have to do with System.Windows.Forms. I cannot tell whether that is what I'm supposed to be using, or if there's some other way to get keyboard input.

So my question is: How do I get input from the keyboard in C# MVC while the VS2010 debugger is running? If there is an alternative or a workaround that someone is aware of that will allow me to give my code access to those values while it is running on my local machine, I would also welcome any suggestions.

Thanks to everyone in advance! - Eli

I don't think that that is a realistic way for a production environment, but I put together a OAuth 2 Client myself and used a custom protocol (ie oauth://?code=...) that was called by the browser. This required registry entries (where "oauthclientcode" is the protocol name):

 [HKEY_CLASSES_ROOT\oauthclientcode]
@="URL:oauthclientcode Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\oauthclientcode\shell]

[HKEY_CLASSES_ROOT\oauthclientcode\shell\open]

[HKEY_CLASSES_ROOT\oauthclientcode\shell\open\command]
@="\"C:\\PATH_TO_EXE\" authresponse %1"

The Browser redirected to my application with the code as a parameter. I then parsed the input in my Main method.

Source of the OAuth2 Client if interested: https://github.com/Excape/oAuth2TestClient

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