Dan McCoy

Dan McCoy

  • NA
  • 8
  • 0

Detecting a failed proxy authentication

Sep 26 2007 8:11 AM
Hello

I have a windows application written in C# that makes several calls to some web services I have also written.
Both the application and the services work fine. The problem is with our proxy server.

When in the development environment, there is no need to set up and use any proxy details, but when I deploy this to a live environment, the app needs the proxy details.
I have already got this to work, but I have been simply commenting the section of code that sets up the proxy details in and out when switching environments.

What I really want to be able to do is first attempt to call my web service without using the proxy, and if this fails, then prompt the user for a username and password before trying again, this time using the proxy.

So far I have wrapped the webservice call in a try-catch block to catch "WebExceptions".
The only way I can see at the moment to tell if the exception is a failed proxy authentication (and not any other kind of problem) is to search the exceptions message for the string "Proxy Authentication Required".

Is there a better way the check if the exception is definitely being thrown because of a proxy authentication problem and not some other kind of problem?
If something else was wrong I wouldn't want to assume the user has input a bad password and continue to prompt them again and again.