1

I have secured map services with AGS. I also have the proxy.config, proxy.ashx, and web.config in my application. My map layers display OK using the proxy. When I try to display my legend using the proxy map layers, a login dialog show up and the legend does not display. If I enter my user and password the legend displays. When I use unsecured services from an AGS server the legend displays fine.

Has anyone experienced this?

this is my proxy code:

esriConfig.defaults.io.proxyUrl = 'proxy/proxy.ashx'; esriConfig.defaults.io.alwaysUseProxy = false;

this i my toc.js for create legend:

    _getLegendIconUrl: function(legend)
   {
  var src = legend.url;
  // in some cases NULL value may cause #legend != #of renderer entry.
  if (src != null && src.indexOf('data') == -1) 
   {
    if ((!has('Microsoft Internet Explorer') || has('Microsoft Internet Explorer') >= 9) && legend.imageData && legend.imageData.length > 0) 
    {
      src = "data:image/png;base64," + legend.imageData;
    } else {
      if (src.indexOf('http') !== 0) 
      {

        // resolve relative url
        src = 'http://localhost/proxy.ashx?'+ this.rootLayer.url + '/' + this.serviceLayer.id + '/images/' + src;

      }
      if (this.rootLayer.credential && this.rootLayer.credential.token ){
        src = src + "?token=" + this.rootLayer.credential.token;
      } else if (esriConfig.defaults.io.alwaysUseProxy){
        src = esriConfig.defaults.io.proxyUrl+ "?"+src;

      }
    }
  }
  return src;
},

when i comment this function, the login dialog box not appear, and legend not appear

   map.on('layers-add-result', tocRun);
   function tocRun(evt)
   {
     toc_demarcationLayer = new TOC({
        map: map,
        layerInfos: [{
            layer: demarcationLayer,
            title: "Sempadan Pentadbiran", 
            collapsed: true
        }]
    }, 'legendDiv1'); 

    toc_demarcationLayer.startup();
    console.log("start toc demarcationLayer");

    toc_demarcationLayer.on('load', function(){
        if (console) 
            console.log('TOC demarcationLayer loaded');             
    });

    toc_demarcationLayer.on('toc-node-checked', function(evt){
        if (console) {
            console.log("TOCNodeChecked, rootLayer:"
            +(evt.rootLayer?evt.rootLayer.id:'NULL')
            +", serviceLayer:"+(evt.serviceLayer?evt.serviceLayer.id:'NULL')
            + " Checked:"+evt.checked);
            if (evt.checked && evt.rootLayer && evt.serviceLayer){
                // evt.rootLayer.setVisibleLayers([evt.serviceLayer.id])
            }
        }
    });    
  • can you please clarify exactly what the problem is? You say that the legend and layers appear when you enter your credentials, which sounds like the expected behaviour, so I'm unclear as to what your exact question is. Thanks – Stephen Lead Jun 29 '16 at 3:50
  • My issue for this TOC widget is that it is not working for my https website. There are me to put username and password, i already save the token for the https web services in my application. – wan Jun 29 '16 at 8:32
  • Can you please edit your question to include the minimum code required for us to reproduce this problem? See stackoverflow.com/help/mcve for some examples – Stephen Lead Jun 29 '16 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.