Making WebPI work with proxy authentication
Recently I had to use WebPI on a machine behind a proxy which required authentication. After some time with google all I have found was information, that WebPI doesn't support authenticated proxies. As I really needed the tool, I decided to try find some workaround.
First step was to get the offline installer for WebPI (it's available here). After installation, the first run attempt resulted in following error:
First step was to get the offline installer for WebPI (it's available here). After installation, the first run attempt resulted in following error:
---------------------------The 407 error code stands for proxy authentication failure. If you are lucky, all what you need to do is enabling default credentials for proxy authentication. This can be easily done by modifying WebPlatformInstaller.exe.config file:
Microsoft Web Platform Installer
---------------------------
Url 'https://go.microsoft.com/fwlink/?LinkId=193533' returned HTTP status code: 407
---------------------------
OK
---------------------------
<configuration>Things are getting a little bit more complicated, when you have to provide specific user and password combination for basic proxy authentication. The defaultProxy element can have a child element module, which can be used for adding a new proxy module to application. Such a proxy module is nothing more than a class which implements IWebProxy interface:
...
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true" />
</system.net>
...
</configuration>
namespace WebPI.NetThe GetSystemWebProxy method guarantees support for IE proxy settings (automatically detect proxy settings, automatic configuration script, manual proxy server settings and advanced manual proxy server settings). Now only a small change to WebPlatformInstaller.exe.config file is needed:
{
public class AuthenticatedProxy : IWebProxy
{
public ICredentials Credentials
{
//Put your user name and password into credentials
get { return new NetworkCredential("user", "password"); }
set { }
}
public Uri GetProxy(Uri destination)
{
//Proxy URI will be taken from the current user's IE proxy settings
return WebRequest.GetSystemWebProxy().GetProxy(destination);
}
public bool IsBypassed(Uri host)
{
return false;
}
}
}
<configuration>That's it. This solution has been tested only on one machine but it has completely resolved the problem of proxy authentication for me, I hope it will do the same for some of you.
...
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="false">
<module type="WebPI.Net.AuthenticatedProxy, WebPI.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=79a8d77199cbf3bc" />
</defaultProxy>
</system.net>
...
</configuration>