public string GetToken(string uri)
{
foreach (ServerUrl su in serverUrls)
{
if (su.MatchAll && uri.StartsWith(su.Url, StringComparison.InvariantCultureIgnoreCase) && su.DynamicToken)
{
// Code to dynamically get the token
string tokenService = string.Format("https://{0}/arcgis/tokens?request=getToken&username={1}&password={2}&expiration=30", su.Host, su.UserName, su.Password);
string token;
// This script is added to force the application to certify the SSL script (if for example you have a self certificate on server)
System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
};
System.Net.WebRequest tokenRequest = System.Net.WebRequest.Create(tokenService);
System.Net.WebResponse tokenResponse = tokenRequest.GetResponse();
System.IO.Stream responseStream = tokenResponse.GetResponseStream();
System.IO.StreamReader readStream = new System.IO.StreamReader(responseStream);
token = readStream.ReadToEnd();
return token;
}
else if (su.MatchAll && uri.StartsWith(su.Url, StringComparison.InvariantCultureIgnoreCase))
{
return su.Token;
}
else
{
if (String.Compare(uri, su.Url, StringComparison.InvariantCultureIgnoreCase) == 0)
return su.Token;
}
}
if (mustMatch)
throw new InvalidOperationException();
return string.Empty;
}
<serverUrl url ="https://212.147.136.135/ArcGIS/rest/services/DoEHLG/ACTIVITIES/FeatureServer" matchAll="true" dynamicToken="true" host="https://localhost/imds/" userName="USERNAME" password="PASSWORD"> </serverUrl>
esriConfig.defaults.io.alwaysUseProxy = true;
featureLayer = new esri.layers.FeatureLayer("https://212.147.136.135/ArcGIS/rest/services/DoEHLG/ACTIVITIES/FeatureServer/0", {
mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
outFields: ["*"],
id: "featureLayer"
});
Error: Unable to load proxy.ashx?https://212.147.136.135/ArcGIS/rest/services/DoEHLG/ACTIVITIES/FeatureServer/0/query status:403 http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.3 Line 14
// This script is added to force the application to certify the SSL script (if for example you have a self certificate on server)
System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
};
<serverUrl url ="https://wsbv7/WebGIS/rest/services..."
<serverUrl url ="http://wsbv7/WebGIS/rest/services..."