views:

106

answers:

1

I have two ASP.NET projects in my solution, and run on different localhost ports when I start debugging. I have a generic handler in site A, which is called by site B:

String url = "http://localhost:1234/UrlOnSiteA.ashx";
WebClient client = New WebClient();
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.OpenRead(url);

The OpenRead call throws an exception with a 500 error, and I don't know why. The error message is:

System.Net.WebException: The remote server returned an error: (500) Internal Server Error.

Other info:

  • A breakpoint on the very first line of the handler code isn't hit.
  • The handler runs properly (and hits the breakpoint) when its URL is used in a browser.
  • Visual Studio 2008 Professional, running .NET 2.0 sites.

I suspect it's a configuration issue. Any ideas?

+1  A: 

I'd diagnose this first by figuring out what's causing the exception. Look at the Response property of the WebException, and read the HTML returned. Any clues? (You may need to disable custom errors in your web.config to see the actual error response.)

Another approach to get the same response info would be to use Fiddler, and set the proxy of your WebClient call to the Fiddler proxy address. Then you can use fiddler to see the response HTML.

A slightly different approach would be to change the Exceptions settings in Visual Studio to break into the debugger whenever a WebException is thrown. You can do this from the Debug...Exceptions... dialog box.

Justin Grant