Using ClickOnce and a proxy server
ClickOnce is Microsoft's technology for deploying applications. ClickOnce applications can check for new versions as they become available and automatically replace any updated files, which is very convenient.
It so happens that to control user access to the Internet and external network resources, a proxy server is used (with or without authentication). ClickOnce provides support for integrated proxy authentication on Windows starting with the .NET Framework 3.5, but does not support other authentication protocols, such as Basic Authentication or Basic Authentication.
If authentication is not used, we can configure the proxy using the defaultProxy element :
But if the computer is configured to use a proxy server that requires authentication, we will receive the following error when trying to update, even if we indicate our Credentials:
This is because every time a file is downloaded using the SystemNetDownloader class , credentials are reset to default data.
We solve this problem as follows:
He works in a project that uses ClickOnce updates and calls to WCF services.
It so happens that to control user access to the Internet and external network resources, a proxy server is used (with or without authentication). ClickOnce provides support for integrated proxy authentication on Windows starting with the .NET Framework 3.5, but does not support other authentication protocols, such as Basic Authentication or Basic Authentication.
If authentication is not used, we can configure the proxy using the defaultProxy element :
…
… … />
But if the computer is configured to use a proxy server that requires authentication, we will receive the following error when trying to update, even if we indicate our Credentials:
The remote server returned an error: (407) Proxy authentication required.
This is because every time a file is downloaded using the SystemNetDownloader class , credentials are reset to default data.
We solve this problem as follows:
Create your own proxy class: CustomUserProxy
public class CustomUserProxy : IWebProxy
{
private WebProxy _webProxy;
public CustomUserProxy(Uri uri)
{
_webProxy = new WebProxy(uri);
}
public ICredentials Credentials
{
get { return _webProxy.Credentials; }
set { }
}
public Uri GetProxy(Uri destination)
{
return _webProxy.GetProxy(destination);
}
public bool IsBypassed(Uri host)
{
return _webProxy.IsBypassed(host);
}
///
/// Альтернативный метод, который устанавливает Credentials
///
/// Учетные данные для аутентификации
public void SetCredentials(ICredentials credentials)
{
_webProxy.Credentials = credentials;
}
}
We use our proxy:
Uri uriProxy = new Uri("http://myproxy.ent:808");
CustomUserProxy customProxy = new CustomUserProxy(uriProxy);
customProxy.SetCredentials(new NetworkCredential("Login", "Password"));
WebRequest.DefaultWebProxy = customProxy;
He works in a project that uses ClickOnce updates and calls to WCF services.