<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: FeatureLayer with Tokens in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080913#M10300</link>
    <description>&lt;P&gt;In this code snippet, how are you giving the FeatureLayer the security token (line 17)?&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jul 2021 16:15:25 GMT</pubDate>
    <dc:creator>JeffBoyton</dc:creator>
    <dc:date>2021-07-20T16:15:25Z</dc:date>
    <item>
      <title>FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1078824#M10271</link>
      <description>&lt;P&gt;I am connection to a Map Service that requires a token and this code works to get the list of layers (where url is something like&amp;nbsp;&lt;A href="http://myhost/arcgis/rest/services/MapServer?token=abcdefg" target="_blank"&gt;http://myhost/arcgis/rest/services/MapServer?token=abcdefg&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;using (var client = new HttpClient())&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; client.BaseAddress = new Uri(url + "&amp;amp;f=pjson");&lt;BR /&gt;&amp;nbsp; &amp;nbsp; client.DefaultRequestHeaders.Accept.Clear();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; return client.GetAsync("").Result;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;I then want to go through each layer and add it as a feature layer to a map (where layerUrl looks like&amp;nbsp;&amp;nbsp;&lt;A href="http://myhost/arcgis/rest/services/MapServer?token=abcdefg" target="_blank"&gt;http://myhost/arcgis/rest/services/MapServer/5?token=abcdefg)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Uri serviceUri = new Uri(layerUrl);&lt;BR /&gt;FeatureLayer layer = new FeatureLayer(serviceUri);&lt;/P&gt;&lt;P&gt;await layer.LoadAsync();&lt;BR /&gt;Map.OperationalLayers.Add(layer);&lt;/P&gt;&lt;P&gt;This does not seem to be working.&amp;nbsp; I am getting no errors, but the layer is also showing no features.&amp;nbsp; Is it obvious what I am doing wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 17:53:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1078824#M10271</guid>
      <dc:creator>JeffBoyton</dc:creator>
      <dc:date>2021-07-14T17:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1079493#M10274</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Is this a custom token parameter that is specific to your environment?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 22:33:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1079493#M10274</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-15T22:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1079502#M10275</link>
      <description>&lt;P&gt;No, this would be a security token created for a 'secure' map service.&amp;nbsp; I am actually simulating the existence of this token parameter (this is a customer environment I do not have access to) by putting '?blah=blah' at the end of the REST url.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 22:41:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1079502#M10275</guid>
      <dc:creator>JeffBoyton</dc:creator>
      <dc:date>2021-07-15T22:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1079516#M10276</link>
      <description>&lt;P&gt;Do you have the credentials for the user's ArcGIS Server (username and password)?&lt;/P&gt;&lt;P&gt;If yes, then you can try using the following code to generate tokens&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;MyView1.Map = new Map(Basemap.CreateImagery());
Esri.ArcGISRuntime.Security.AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(
    async info =&amp;gt; await Esri.ArcGISRuntime.Security.AuthenticationManager.Current.GenerateCredentialAsync
                                (info.ServiceUri,
                                    "username",
                                    "password", info.GenerateTokenOptions));
var featureURL = "http://myhost/arcgis/rest/services/MapServer/5";
var layer = new FeatureLayer(new Uri(wms));
await layer.LoadAsync();
MyView1.Map.OperationalLayers.Add(layer);&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 15 Jul 2021 23:19:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1079516#M10276</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-15T23:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1079518#M10277</link>
      <description>&lt;P&gt;I do not have a username/password (which is why I am using a generated token).&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 23:33:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1079518#M10277</guid>
      <dc:creator>JeffBoyton</dc:creator>
      <dc:date>2021-07-15T23:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080380#M10293</link>
      <description>&lt;P&gt;The recommended way to authenticate is to generate tokens using the AuthenticationManager as done above. But if you already have a token, you can add it to the outgoing request by doing something like this&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ArcGISHttpClientHandler.HttpRequestBegin += (a, b) =&amp;gt;
{
    if (b.RequestUri.OriginalString.Contains(mapserverUrl))
    {
        b.RequestUri = new Uri(b.RequestUri + "token=abcdefg");
    }

    //OR try adding the token as part of the header

    if (b.RequestUri.OriginalString.Contains(mapserverUrl))
    {
        b.Headers.Add("X-Esri-Authorization", "My Custom Header");
    }
};
ArcGISHttpClientHandler.HttpResponseEnd += (a, b) =&amp;gt;
{
    // Check for response codes here
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 17:29:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080380#M10293</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-19T17:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080385#M10294</link>
      <description>&lt;P&gt;Checking the layerViewState for errors is a good way to debug your code. The spatial reference of the features and that of the map should be the same for the features to be displayed on the map. Also, if you want to parse the MapServer to get the layer ids, you can try doing something like this (using ServiceGeoDatabase instead)&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var sgdb = new ServiceGeodatabase(new Uri(mapserverUrl));
await sgdb.LoadAsync();
​
var map = new Map(Basemap.CreateTopographic());
​
MyMapView.LayerViewStateChanged += (a, b) =&amp;gt;
    {
        var error = b.LayerViewState.Error ?? b.Layer.LoadError;
        if (error != null)
            MessageBox.Show(error.Message, error.GetType().Name);
    };
​
MyMapView.Map = map;
​
foreach(var info in sgdb.ServiceInfo.LayerInfos)
{
    var layer = new FeatureLayer(new Uri($"{mapserverUrl}/{info.Id}"));
    await layer.LoadAsync();
    map.OperationalLayers.Add(layer);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 17:33:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080385#M10294</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-19T17:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080913#M10300</link>
      <description>&lt;P&gt;In this code snippet, how are you giving the FeatureLayer the security token (line 17)?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 16:15:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080913#M10300</guid>
      <dc:creator>JeffBoyton</dc:creator>
      <dc:date>2021-07-20T16:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080989#M10301</link>
      <description>&lt;P&gt;If you use the authentication code mentioned in my previous reply then every time a request is made to the requestUri, the Clienthandler will kick in and add the token/authorization header to the outgoing request.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 18:47:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1080989#M10301</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-20T18:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1516776#M12944</link>
      <description>&lt;P&gt;Thanks this is how I've done !&lt;/P&gt;&lt;P&gt;Just using an UriBuilder to not mess with other get parameters.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var uriBuilder = new UriBuilder(b.RequestUri.AbsoluteUri);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
//apply token
query["token"] = "&amp;lt;add your token here&amp;gt;";
uriBuilder.Query = query.ToString();
//update uri
b.RequestUri = uriBuilder.Uri;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2024 16:10:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1516776#M12944</guid>
      <dc:creator>Marc_Alx</dc:creator>
      <dc:date>2024-08-08T16:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureLayer with Tokens</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1680174#M13852</link>
      <description>&lt;P&gt;As of 200.8.1 you should switch to the following method:&lt;/P&gt;&lt;P&gt;1. Implement &lt;STRONG&gt;IHttpMessageInterceptor&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class MyInterceptor: IHttpMessageInterceptor {
   public Task&amp;lt;HttpResponseMessage&amp;gt; SendAsync(HttpMessageInvoker invoker, HttpRequestMessage message, CancellationToken cancellationToken)
   {
        //work with message here (to add token in RequestUri...)
        return invoker.SendAsync(message, cancellationToken);
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Resgister your interceptor at ArcGIS initialization:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ArcGISRuntimeEnvironment.Initialize((conf) =&amp;gt; {
  conf.ConfigureHttp((httpConf)=&amp;gt;httpConf.UseHttpMessageInterceptor(new MyInterCeptor()));
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jan 2026 08:46:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/featurelayer-with-tokens/m-p/1680174#M13852</guid>
      <dc:creator>Marc_Alx</dc:creator>
      <dc:date>2026-01-27T08:46:24Z</dc:date>
    </item>
  </channel>
</rss>

