Thursday, July 21, 2011

Workaround for authenticating application to Proxy Server without modifying the app itself

This week we ran into an issue with proxy servers. The server needed authentication and our sample code does not allow any authentication mechanism for that.. Thanks to my colleague Ajay who taught me how to do that with a mere simple configuration in web.xml

.Net's default web proxy does not have the UseDefaultCredentials flag switched on by default. It's false. This property if true, authenticate to the WebService/Proxy using the credentials of the currently logged on user and for client applications, this is the desired behavior in most scenarios.

So all you have to do is , put this in web.config or app.config within <configuration> tag :
<system.net>
  <defaultProxy
    useDefaultCredentials="true" >
  </defaultProxy>
</system.net>

This workaround can work in testing environment, but might not work in production environment, as it picks current user credentials to authenticate to proxy server. But in production environment, the current user(IIS Admin/Service account) may not have the access to the internet.

No comments:

Post a Comment