Some organizations use a web proxy server to connect to the Internet. A proxy server (or "forward proxy") can present a problem for Essentials when you want to use Internet resources in your sites, as Essentials won't automatically be configured to use the proxy to access the Internet. If you are able to access Internet map services, but are unable to add them to an Essentials site, then you may have to configure Essentials to use your organization's proxy server.
Solution:
Connecting to a Simple Proxy Server
If the proxy does not require authentication, we just need to configure Essentials to use the proxy. This is done in the web.config files for both the REST application and the Manager application.
Add the following XML to the web.config files as a child of the <system.net> tag:
<defaultProxy> <proxy proxyaddress="http://proxyserver:port" bypassonlocal="True" /> </defaultProxy>
...where "proxyserver:port" are the address and port of the HTTP proxy server on your network.
Your IT department can supply the correct values, or you can match it to whatever is found in your Internet Options for a web browser.
Connecting to an Authenticated Proxy Server
If your proxy does require authentication, we must provide some code to Essentials to instruct it how to connect to the proxy server. This code will go into the "App_Code" folder within the Essentials REST or REST Manager application. This folder won't exist in a normal install, since it would contain uncompiled code and Essentials is a precompiled application.
The following steps outline the process of connecting to an authenticated proxy with a single username and password:
- Create an "App_Code" folder in the REST and REST Manager application. This folder will be beside the "App_Data" folder within the web application's root folder.
- Create a new .cs file named AuthenticatedProxy.cs in the new App_Code folders.
- Paste the following code into the AuthenticatedProxy.cs files:
using System; using System.Net; namespace LocalSecurity { public class AuthenticatedProxy : IWebProxy { public ICredentials Credentials { get { return new NetworkCredential("[PROXYUSER]", "[PROXYPASSWORD]"); } set { } } public Uri GetProxy(Uri destination) { return new Uri("http://[PROXYHOST]:8080"); } public bool IsBypassed(Uri host) { return false; } } }
Note: If your user is member of a domain, you can use: get { return new NetworkCredential("[PROXYUSER]", "[PROXYPASSWORD]", "[PROXYDOMAIN]"); } Instead of: get { return new NetworkCredential("[PROXYUSER]", "[PROXYPASSWORD]"); }
- Replace the [PROXYUSER], [PROXYPASSWORD], [PROXYHOST] and :8080 values with a valid proxy user, the corresponding password, the address of your proxy server, and its port.
- Configure Essentials REST and REST Manager to use the proxy by inserting the following XML into the web.config file as a child of the <system.net> tag:
<defaultProxy enabled="true" useDefaultCredentials="false"> <module type="LocalSecurity.AuthenticatedProxy, App_Code" /> </defaultProxy>
- Save the web.config file. Essentials will now use the credentials coded into the AuthenticatedProxy class when connecting to a proxy server.
Note: Addresses must be added explicitly, wildcard characters are not accepted. Also, you may need to add a resource's hostname, fully-qualified-domain-name and/or IP address, depending on your Essentials and network configurations.
using System; using System.Net; using System.Collections.Generic; namespace LocalSecurity { public class AuthenticatedProxy : IWebProxy { public ICredentials Credentials { get { return new NetworkCredential("[PROXYUSER]", "[PROXYPASSWORD]"); } set { } } public Uri GetProxy(Uri destination) { return new Uri("http://[PROXYHOST]:8080"); } public bool IsBypassed(Uri host) { List<string> hosts = new List<string>(); hosts.Add("127.0.0.1"); hosts.Add("localhost"); hosts.Add("someOtherHost"); hosts.Add("host.domain.com"); if(hosts.Contains(host.Host)) { return true; } else { return false; } } } }
Comments
0 comments
Article is closed for comments.