Telerik blogs

Using proxy on .NET

When deploying you app you may find that some users are located behind proxy servers or similar. The EQATEC Analytics monitor will attempt to connect to the servers using a standard HTTP connection and will optionally setup specific proxy settings if you have configured it on the AnalyticsMonitorSettings instance. However, using these specific settings are typically not desirable unless you know the precise proxy setup of your end users or have a programmatic way of obtaining it.  What you typically want is to have your application use the default proxy settings of the underlying system when connecting. 

Proxy setup by configuration file

In .NET the default proxy behavior of your application can be altered by using the configuration file. The configuration file offers a specific element for setting up your default proxying within the application. You can find the full specification for the this setup here.

For instance, you may want to use the default credentials when authenticating through the proxy server. Passing the default credentials to the proxy server is turned off by default by can be enabled by adding the following code to your application config:

<system.net>
    <defaultProxy useDefaultCredentials="true" />
</system.net>

Proxy setup by code

When the monitor is delivering data to the EQATEC Analytics servers it uses the standard HttpWebRequest in the BCL. When created an HttpWebRequest instance inherits the default proxy settings  exposed from the WebRequest.DefaultWebProxy static property. You can alter this default by assigning your own proxy to this static property so if you want to use the default credentials for authentication you can do the following

var webProxy = WebProxy.GetDefaultProxy();
webProxy.UseDefaultCredentials = true;
WebRequest.DefaultWebProxy = webProxy;

The choice between configuration and code is really up to your individual application. Please note that the monitor, unless explicitly configured otherwise through the proxy settings, uses the default proxy within your application.  This means that ultimately the ability to actually obtain connectivity and reach the servers is a responsibility that falls outside the scope of the monitor and lays with the hosting application.

Proxy setup in COM

If you are using the COM monitor you are actually using a customized version of the .NET monitor that has an exposed surface on COM. For that reason the issues with proxy setup are similar when using the COM monitor. Since the COM exposed library is utilized from your (non .NET) application the proxy settings cannot be handled in code but must be handled using the configuration file. 

For COM integration you should create a settingsfile named [yourapplication].exe.config with the proxy configuration above. When integrating into the COM library these settings will get picked up and utilized by the .NET runtime. For details you can refer to this question or this blog post.

Troubleshooting connectivity

Try EQATEC Application Analytics. It's Free!

 

About the Author

Søren Enemærke

Søren Enemærke has worked as lead developer of the EQATEC Application Analytics service ever since its inception in 2008, and continues to be deeply involved as a software developer at Telerik Denmark. Søren has a M.Sc. in CS and more than a decade of software development experience, primarily focused on C#, web and database technologies. Søren enjoys reducing technical debt, introducing automation wherever possible and the simple act of sitting down and churning out workable code.

Comments

Comments are disabled in preview mode.