Select to view content in your preferred language

How do you reference the proxy.ashx page?

19528
25
08-09-2011 09:26 AM
MatthewGerbrandt
New Contributor II
Hello there. I've got some secured ArcGIS Services that require a token.  I've got my proxy.ashx and proxy.config pages in place and configured.

The last thing I need to do is figure out how to get my JS/HTML pages to reference those proxy pages and pass the token to the services.

If someone could please post some code or point me to an example, I'd be tremendously grateful.  The info at http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jshelp_start.htm#jshelp/... wasn't helpful because my pages don't have a code-behind page for the C# code.

Thanks a million in advance!!
0 Kudos
25 Replies
MatthewGerbrandt
New Contributor II
Harold - If I add the www, it works.  I get the Google web site.

If I substitute www.google.com with my service's URL, I get

XML Parsing Error: no element found
Location: http://servername/proxy.ashx?http://Server.Name.com/ArcGIS/rest/services/cadaster/ServiceName/MapServer
Line Number 1, Column 1:


Is the problem that the server running the ArcGIS service has a domain name with more dot's in it than is usually expected?

For example, the domain name is: Server.Name.com
Instead of : ServerName.com

saur5784 - I'm running ASP.NET version 4.0.3xxxxxx

Thanks for your help and persistence, guys. I appreciate your help beyond words.
0 Kudos
HaroldBostic
Occasional Contributor II
the domain name should not matter as my domain name has multiple dots.

do you have an  unsecured service on that same server that you can test your proxy page with?  If not, can you turn off ArcGISServer security and test that you can access your services?

After that, turn back on security and....

Can you go to your token url generator and ensure that the uname and pwd you are using can in fact generate a token for that service?

You can verify this by browsing to:
http://Server.Name.com/ArcGIS/rest/services/cadaster/ServiceName/MapServer?token=YourTokenGoesHere

if successful.....
The next step would to remove the dynamic token generation from your proxy config, and use the static one and try to access your service through your browser using the proxy as you did before.

Let me know if you need more clarification for any of the steps above.
0 Kudos
MatthewGerbrandt
New Contributor II
Alrighty... Thanks again, Harold!!

This code works:

<script type="text/javascript">
    dojo.require("esri.map");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("dijit.layout.BorderContainer");
    var map;
    function Init() {

        esri.config.defaults.io.proxyUrl = "../proxy.ashx"; 
        dojo.style(dojo.byId("map"), { width: dojo.contentBox("map").w + "px", height: (esri.documentBox.h - dojo.contentBox("navTable").h - 40) + "px" });
        map = new esri.Map("map");
        
        var CountyDataLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://Server.Name2.com/ArcGIS/rest/services/Counties/MapServer");
        map.addLayer(CountyDataLayer);

        var RestrictedLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://Server.Name2.com/ArcGIS/rest/services/cadaster/ServiceName/MapServer?token=ZwBeUJKkl5L6bSitvEGgRy7hy52NmqBF8GIFCnB-7Lg.");
        map.addLayer(RestrictedLayer);
        
        
        var resizeTimer;
        dojo.connect(map, 'onLoad', function(theMap) {
            dojo.connect(dijit.byId('map'), 'resize', function() {
                clearTimeout(resizeTimer);
                resizeTimer = setTimeout(function() {
                    map.resize();
                    map.reposition();
                }, 500);
            });
        });
    }
    dojo.addOnLoad(Init);
</script>


Taking the token out of the JavaScript and putting it in the proxy.config file does not work:

<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig mustMatch="true">
  <serverUrls>
    <serverUrl url="http://Server.Name2.com/ArcGIS/rest/services/cadaster/ServiceName/MapServer"
               matchAll="true"
               token="ZwBeUJKkl5L6bSitvEGgRy7hy52NmqBF8GIFCnB-7Lg."></serverUrl>
  </serverUrls>
  
</ProxyConfig>


Any ideas?
0 Kudos
SaurabhGupta
New Contributor II

        esri.config.defaults.io.proxyUrl = "../proxy.ashx"; 


Change the URL to a complete server URL : http://servername/proxy.ashx



    <serverUrl url="http://Server.Name2.com/ArcGIS/rest/services/cadaster/ServiceName/MapServer"
  </serverUrls>  


Change the URL above to http://ServerName/ArcGIS/rest




See if above helps.
0 Kudos
HaroldBostic
Occasional Contributor II
In that  case you must generate the token using the ip address of the server in which the proxy resides rather than the url.  i.e. the ip is the referer that should be used.

The new token should work inside the proxy
0 Kudos
MatthewGerbrandt
New Contributor II
Thanks again for your persistence, fellas!  I've made the following changes but still, no luck...

<script type="text/javascript">
    dojo.require("esri.map");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("dijit.layout.BorderContainer");
    var map;
    function Init() {

        esri.config.defaults.io.proxyUrl = "http://gisweb/proxy.ashx"; 
        dojo.style(dojo.byId("map"), { width: dojo.contentBox("map").w + "px", height: (esri.documentBox.h - dojo.contentBox("navTable").h - 40) + "px" });
        map = new esri.Map("map");
        
        var CountyDataLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://Server.Name2.com/ArcGIS/rest/services/Counties/MapServer");
        map.addLayer(CountyDataLayer);

        var RestrictedLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://Server.Name2.com/ArcGIS/rest/services/cadaster/AboriginalUseArea/MapServer");

        map.addLayer(RestrictedLayer);
        
    }
    dojo.addOnLoad(Init);
</script>


<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig mustMatch="true">
  <serverUrls>
    <serverUrl url="http://Server.Name2.com/ArcGIS/rest/"
               matchAll="true"
               host="10.10.10.51"
              token="ZwBeUJKkl5L6bSitvEGgRzZquMaWltg0GZY_xbGzVIA."></serverUrl>

  <serverUrl url="http://www.google.com"
               matchAll="true"></serverUrl>
  </serverUrls>
  
</ProxyConfig>


As far as the proxy.config file goes, I have also tried:

serverUrl url="http://Server.Name2.com/ArcGIS/rest/services"
serverUrl url="http://Server.Name2.com/ArcGIS/rest/services/cadaster"
serverUrl url="http://Server.Name2.com/ArcGIS/rest/services/cadaster/AboriginalUseArea"
serverUrl url="http://Server.Name2.com/ArcGIS/rest/services/cadaster/AboriginalUseArea/MapServer"
serverUrl url="http://10.10.10.51/ArcGIS/rest/services/AboriginalUseArea/"
0 Kudos
HaroldBostic
Occasional Contributor II
Hello,

When you go to

http://Server.Name/ArcGIS/tokens/gettoken.html

And you get the screen like the attached, do you create the token using the ip address of Server.Name?
0 Kudos
HaroldBostic
Occasional Contributor II
Also, is this an externally facing server?  If so, do you have a reverse proxy set up?
0 Kudos
MatthewGerbrandt
New Contributor II
Hello,

When you go to

http://Server.Name/ArcGIS/tokens/gettoken.html

And you get the screen like the attached, do you create the token using the ip address of Server.Name?


I use the server name, not the IP address. I also get the following error message:

Secure connection (SSL) required.


I do not have access to an SSL certificate.  Is that a requirement?  Sorry if that's a dumb question.
0 Kudos
HaroldBostic
Occasional Contributor II
I have only gotten my proxy to work when I use the ip address of the server that the proxy resides I never gotten the proxy page to work with the server name

a potential resource
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Configuring_the_Token_Service/00040000...

How were you generating your token previously?

you can check out this link, where it shows you how to set the RequireSSL flag, you would set yours to false after reading about how this is only recommended in a dev environment

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Configuring_the_Token_Service/00040000...
0 Kudos