AnsweredAssumed Answered

Legend problems with secured services when migrating to 3.0/3.1

Question asked by btfou on Aug 24, 2012
Latest reply on Aug 30, 2016 by JRonde
I add dynamic and feature layers when the application loads by iterating through an object literal like such:
var config = {     token: SOME_TOKEN,     layers: [         {             type: 'dynamic',             url: 'http://MY_URL/ArcGIS/rest/services/Slope/MapServer',             token: true,             name: 'Slope',             id: 'slope',             visible: false,             opacity: 0.5,             imageFormat: 'png32',             dpi: 96,             legend: true,             parcelLabelControl: false,             subLayerControl: false,             info: true,             infoHtml: 'This layer displays slopes.'         },         {             type: 'feature',             url: 'http://MY_URL/ArcGIS/rest/services/Fire_Hydrants/MapServer/0',             token: true,             name: 'Fire Hydrants',             id: 'firehydrants',             visible: false,             opacity: 1,             imageFormat: 'png32',             dpi: 96,             legend: true,             itTitle: 'Fire Hydrant',             itContentType: 'function',             itContentText: '',             itContentFunction: 'config.featureFunctions.hydrants.infoTemplate'         }     ] }

If a token is required it's added to the url when the layer object is created. Layers are pushed to the legend when legend is set to true. Through 2.8 this worked fine, but not in 3.0+. I did some digging and discovered that in 2.8 the legend widget makes calls to the map service's legend REST like so:

In 3.0+ the call is:

Notice the token query string is represented twice with two ?. AGS returns a 'invalid token' error. Seems to me there's an error forming the url for the legend REST call. Perhaps getting the service's base url from SOME_LAYER.url instead of SOME_LAYER._url.path.

Any help would be appreciated as this is a roadblock as I migrate to 3.0+. Thanks.