Skip to main content

Connecting to online map services via proxy server

Comments

7 comments

  • Permanently deleted user
    Hi there,   It is possible to configure ASP.NET (or .NET in general) to use a proxy server with specific credentials, although it's not as easy as just using an anonymous one.   I borrowed the instructions from Stack Overflow (http://stackoverflow.com/questions/186800/is-it-possible-to-specify-proxy-credentials-in-your-web-config) and got them to work with Essentials as follows:   1) Create an App_Code folder in Essentials.   2) Paste the following code into a new .cs file in the App_Code folder (I named it "ExampleProxy.cs")   using  System; using  System.Net;

     

     

    namespace   ExampleSecurity  

     

    {  

     

        public class   ExampleProxy : 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 ;  

     

            }  

     

        }  

     

    }  

     

     

    3) Set [PROXYUSER], [PROXYPASSWORD] and [PROXYHOST] as appropriate.  If your web proxy listens on a port other than 8080, set that too.

    4) Configure Essentials (either ADF or REST) to use your new proxy by adding this to your web.config file:

    <system.net>

     

      <defaultProxy enabled="true" useDefaultCredentials="false">

     

        <module type="ExampleSecurity.ExampleProxy, App_Code" />

     

      </defaultProxy>

     

    </system.net>

    5) Save the web.config file.  Essentials will now be able to use the proxy with the credentials specified.

    As the stackoverflow article states, this is a functional example without any configuration in the web.config.  But, it did work for me here with my test squid proxy.

    Good luck,

    -Malcolm

     

    0
  • Permanently deleted user
    Thanks, that worked perfectly. cheers Rowan

     

    0
  • Permanently deleted user
    Can I clarify the locations of the files?

     

     

    App_Code is off the Essentials directory (e.g. C:\inetpub\wwwroot\Geocortex\Essentials)?

     

     

    The web.config file should also be in the above directory?

     

     

    Excuse my lack of web programming...
    0
  • Permanently deleted user
    Hi Peter,   The App_Code folder belongs in the webapp that will be doing the proxy negotiation.   This is either C:\inetpub\wwwroot\Geocortex\Essentials\REST (for Essentials REST elements) or C:\inetpub\wwwroot\Geocortex\Essentials\Web (for Essentials ADF elements).   The "Essentials" folder is not an application so code won't run from there.   Regards, -Malcolm

     

    0
  • James Brink

    Malcolm, we created the App_Code folder and put the .cs file in it, and modified the web.config as you suggested. We still get the error message that "The host 'http://kgisserver/ArcGIS/rest/services' does not appear to reference a valid ArcGIS Server instance. When specifying a URL please ensure you provide the full URL to an ArcGIS Server Services Directory. Underlying error: Unable to connect to the remote server" in manager.

    Any ideas?

    Thanks

    Jimmy Brink

     

     
    0
  • Permanently deleted user

    Hi Jimmy,

    The URL http://kgis/ ... is a local address, so you may have to flesh out the IsBypassed method in the proxy module to add logic to enable or disable the proxy.

    Your proxy may only be required for addresses outside your organization; thus, the IsBypassed method should return true for URIs that shouldn't be proxied.  Best to confirm that with the IT department who sets up the proxy.  They should also have access to the proxy log files and can tell you where (if anywhere) your requests are going.

    Regards,

    -Malcolm

    0
  • Permanently deleted user

    Hi Malcolm

     

    I know this is a very old post, but I think what you're talking about with fleshing out the IsBypassed method is just what I want to do.  I've used this code to allow access to external web services and it seems to work fine, but now I find that a workflow that performs a Query Task on a local service is no longer working.  The trouble is I have no experience with this type of code - do you have any example of what the code would need to look like?  Logically I guess it would be along the lines of if host is like .xxxxxx then return true, else return false.  FYI - I'm using Essentials 4.2.

     

    Many thanks,

    Stuart

    0

Please sign in to leave a comment.