Skip to content

Prerequisites

Before starting this tutorial:

Optionally, you may want to install the ArcGIS Maps SDK for .NET to get access to project templates in Visual Studio (Windows only) and offline copies of the NuGet packages.

Steps

Your app needs an access token to use location services. An API key is a long-lived access token that authorizes your application to access secure services, content, and functionality in ArcGIS.

  1. Complete the Create an API key tutorial to get a new API key access token.

    • Ensure that the necessary privileges are enabled for the functionality your app requires. If you need to use basemaps, for example, enable access to the Basemap styles service: Location services > Basemaps > Basemap styles service.

    • Copy the access token for use in the next step.

  2. Add the API key access token to your app using the instructions below for either WPF or .NET MAUI.

    1. In your project's Solution Explorer, expand the node for App.xaml, and double-click App.xaml.cs to open it.

    2. In the App class, add an override for the OnStartup() function to set the ApiKey property on ArcGISRuntimeEnvironment.

      App.xaml.cs
      Use dark colors for code blocks
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
          public partial class App : Application
          {
      
              protected override void OnStartup(StartupEventArgs e)
              {
                  base.OnStartup(e);
      
                  // Set the access token for ArcGIS Maps SDK for .NET.
                  Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_ACCESS_TOKEN";
      
              }
      
          }
      }
    3. Replace "YOUR_ACCESS_TOKEN" in the example above with the API key access token you created earlier.

    4. Save and close the App.xaml.cs file.

For more information, see API key authentication.

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.