AnsweredAssumed Answered

IdentityManager (3.16 vs 3.18) - How to find whether the map service is private or public?

Question asked by bforbhavin on May 23, 2018
Latest reply on May 23, 2018 by rscheitlin

ArcGIS Server supports private and public service both. How can I find out whether the map service is public or private in the code?

 

I have written code to perform silent authentication by avoiding to display the sign-in dialog. My expectation is to get an error then I can generate the token based on the error code.

 

This behavior I had implemented with ArcGIS Javascript API 3.16compact and it worked fine by querying to the mapservice url and generate token if it returns an error. But the same code doesn't work with 3.18compact. Because it challenges the user for credentials (in 3.18compact) and displays the sign-in dialog. So, the request doesn't go to error handler function. It appears the IdentityManager works different way in ArcGIS Javascript API 3.16 vs 3.18.

 

Notice the behavior in the following code by changing from 3.18 to 3.16 and vice versa.

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title></title>

<link rel="stylesheet" href="http://js.arcgis.com/3.18compact/dijit/themes/tundra/tundra.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.18compact/esri/css/esri.css">
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
#map{ margin: 0; padding: 0; }
#controls {
position: absolute;
height: 80px;
font-family: arial;
bottom: 10px;
margin: 5px;
padding: 5px;
z-index: 40;
background: #fff;
color: #444;
width: 440px;
left: 10px;
-moz-box-shadow: 0 0 5px #888;
-webkit-box-shadow: 0 0 5px #888;
box-shadow: 0 0 5px #888;
}
h3 { margin: 0 0 5px 0; border-bottom: 1px solid #444; }
.label { display: inline-block; width: 140px; }
</style>

<script src="http://js.arcgis.com/3.18compact/"></script>
<script>
var app = {};

require([
'esri/map', 'esri/layers/ArcGISDynamicMapServiceLayer', 'esri/tasks/GeometryService', 'esri/request', 'esri/tasks/ProjectParameters'
], function(
Map, ArcGISDynamicMapServiceLayer, GeometryService, esriRequest, ProjectParameters) {
app.map = new Map("map", {
basemap: 'streets'
});

//following is a private map service url
var vMapServiceUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SaveTheBay/MapServer";

esriRequest({
url: vMapServiceUrl,
content: { f: 'pjson'},
handleAs: 'json',
callbackParamName: 'callback'
}).then(function(results) {
var vDynamicLayer = new ArcGISDynamicMapServiceLayer(vMapServiceUrl, {
'id': 'AGSDynamicMapServiceLayer'
});
app.map.addLayer(vDynamicLayer);

app.map.on('layer-add-result', function(layer) {
if (layer.layer.id == 'AGSDynamicMapServiceLayer') {
var vGeometryService = new GeometryService("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"),
vProjectParameters = new ProjectParameters();

vProjectParameters.geometries = [layer.layer.initialExtent];
vProjectParameters.outSR = app.map.spatialReference;
vGeometryService.project(vProjectParameters, function (geometry) {
app.map.setExtent(geometry[0], true);
});
}
});

}, function(errors) {
//expecting to get an error here for request made to private map service
console.log(errors);
});
});
</script>
</head>

<body class="tundra">
<div data-dojo-type="dijit.layout.BorderContainer"
data-dojo-props="design:'headline',gutters:false"
style="width: 100%; height: 100%; margin: 0;">
<div id="map"
data-dojo-type="dijit.layout.ContentPane"
data-dojo-props="region:'center'">
</div>
</div>
</body>
</html>

Outcomes