Home > OS >  Visual studio plugin to intercept time consuming web request
Visual studio plugin to intercept time consuming web request

Time:10-18

This is an asp.net webform website we are developing. In one xx.aspx.cs file, it gets web response from Google server.

var content = new FormUrlEncodedContent(recaptchaDetails);
var response = client.PostAsync("https://www.google.com/recaptcha/api/siteverify", content).Result;
var responseString = response.Content.ReadAsStringAsync().Result;
var obj = JsonConvert.DeserializeObject<RecaptchaResponse>(responseString);

Each time I debug this page in my local machine, Visual Studio fires up the IIS Express to run the server code. While IIS Express process the page, it takes very long time to load the response from Google in my local machine. It is not convenient for debugging.

Here is my thought on resolving this.

  • Change the code while debugging in my local machine. Change it to a mock returned object. But every time I commit the code, I have to roll back this block. There is risk that it may be commited to git server.

    var response = new Xxx()

  • Use Fiddler to intercept this request to Google and return a file from disk.But each time before debugging, I have to open the fiddler.

Is there any Visual Studio plugin or IIS Express plugin to intercept the request to Google and directly return a response from disk file?

CodePudding user response:

This can be done using #if DEBUG, which is called a Conditional Compilation directive.

It is generally best to do a Release build in VS (this creates a DLL with optimized code for all pages), and then deploy the contents of the bin\Release folder to the web server. If you use Web Project -> right click -> Publish... then that should happen automatically.

If you do a manual copy of all source files to IIS, then on IIS the files might or might not run in "DEBUG" mode. I have tried, and in a simple page the Conditional Compilation directive worked fine, with DEBUG not active.

What happens in your case may depend on what is in your web.config, as discussed in this answer but I have not personally tried that.

  • Related