---
title: Enabling AAP for .NET
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > App and API Protection > Enabling App and API
  Protection > Enabling AAP for .NET > Enabling AAP for .NET
---

# Enabling AAP for .NET

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

You can monitor App and API Protection for .NET apps running in Docker, Kubernetes, Amazon ECS, and AWS Fargate.

## Prerequisites{% #prerequisites %}

{% alert level="info" %}
**1-Click Enablement**If your service is running with [an Agent with Remote Configuration enabled and a tracing library version that supports it](https://docs.datadoghq.com/agent/guide/how_rc_works/#enabling-remote-configuration), hover over the **Not Enabled** indicator in the AAP Status column and click **Enable AAP**. There's no need to re-launch the service with the `DD_APPSEC_ENABLED=true` or `--enable-appsec` flags.
{% /alert %}

- The [Datadog Agent](https://app.datadoghq.com/account/settings#agent) is installed and configured for your application's operating system or container, cloud, or virtual environment.
- [Datadog APM](https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/) is configured for your application or service, and traces are being received by Datadog.
- If your service is running with [an Agent with Remote Configuration enabled and a tracing library version that supports it](https://docs.datadoghq.com/agent/remote_config/?tab=configurationyamlfile#enabling-remote-configuration), you can block attackers from the Datadog UI without additional configuration of the Agent or tracing libraries.

## Enabling threat detection{% #enabling-threat-detection %}

### Get started{% #get-started %}

1. **Update your [Datadog .NET library](https://github.com/DataDog/dd-trace-dotnet/releases/latest)** to at least version 2.2.0 for your target operating system architecture.

To check that your service's language and framework versions are supported for AAP capabilities, see [Compatibility](https://docs.datadoghq.com/security/application_security/setup/compatibility/dotnet/).

1. **Enable AAP** by setting the `DD_APPSEC_ENABLED` environment variable to `true`. For example, on Windows self-hosted, run the following PowerShell snippet as part of your application start up script:

   ```
   $target=[System.EnvironmentVariableTarget]::Process
   [System.Environment]::SetEnvironmentVariable("DD_APPSEC_ENABLED","true",$target)
   ```

**Or** one of the following methods, depending on where your application runs:

   {% tab title="Windows self-hosted" %}
In a Windows console:

   ```gdscript3
   rem Set environment variables
   SET CORECLR_ENABLE_PROFILING=1
   SET CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
   SET DD_APPSEC_ENABLED=true
   
   rem Start application
   dotnet.exe example.dll
   ```

      {% /tab %}

   {% tab title="IIS" %}
Run the following PowerShell command as administrator to configure the necessary environment variables in the registry `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment` and restart IIS.

   ```
   $target=[System.EnvironmentVariableTarget]::Machine
   [System.Environment]::SetEnvironmentVariable("DD_APPSEC_ENABLED","true",$target)
   net stop was /y
   net start w3svc
   ```

**Or**, for IIS services exclusively, on WAS and W3SVC with Powershell as an administrator, run:

   ```gdscript3
   $appsecPart = "DD_APPSEC_ENABLED=true"
   [string[]] $defaultvariable = @("CORECLR_ENABLE_PROFILING=1", "CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}", $appsecPart)
   
   function Add-AppSec {
   
       param (
           $path
       )
       $v = (Get-ItemProperty -Path $path).Environment
       If ($v -eq $null) {
           Set-ItemProperty -Path $path -Name "Environment" -Value $defaultvariable
       }
       ElseIf (-not ($v -match $appsecPart)) {
           $v += " " + $appsecPart;
           Set-ItemProperty -Path $path -Name "Environment" -Value $v
       }
   }
   Add-AppSec -path "HKLM:SYSTEM\CurrentControlSet\Services\WAS\"
   Add-AppSec -path "HKLM:SYSTEM\CurrentControlSet\Services\W3SVC\"
   
   net stop was /y
   net start w3svc
   ```

**Or**, to avoid editing registry keys, edit the application settings in the `web.config` file of your application:

   ```xml
   <configuration>
     <appSettings>
           <add key="DD_APPSEC_ENABLED" value="true"/>
     </appSettings>
   </configuration>
   ```

This can also be done at the IIS application pools level in the `applicationHost.config` file, usually in `C:\Windows\System32\inetsrv\config\`:

   ```xml
   <system.applicationHost>
   
       <applicationPools>
           <add name="DefaultAppPool">
               <environmentVariables>
                   <add name="DD_APPSEC_ENABLED" value="true" />
               </environmentVariables>
               (...)
   ```

      {% /tab %}

   {% tab title="Linux" %}
Add the following to your application configuration:

   ```
   DD_APPSEC_ENABLED=true
   ```

      {% /tab %}

   {% tab title="Docker CLI" %}
Update your configuration container for APM by adding the following argument in your `docker run` command:

   ```shell
   docker run [...] -e DD_APPSEC_ENABLED=true [...]
   ```

      {% /tab %}

   {% tab title="Dockerfile" %}
Add the following environment variable value to your container Dockerfile:

   ```Dockerfile
   ENV DD_APPSEC_ENABLED=true
   ```

      {% /tab %}

   {% tab title="Kubernetes" %}
Update your deployment configuration file for APM and add the AAP environment variable:

   ```yaml
   spec:
     template:
       spec:
         containers:
           - name: <CONTAINER_NAME>
             image: <CONTAINER_IMAGE>/<TAG>
             env:
               - name: DD_APPSEC_ENABLED
                 value: "true"
   ```

      {% /tab %}

   {% tab title="Amazon ECS" %}
Update your ECS task definition JSON file, by adding this in the environment section:

   ```json
   "environment": [
     ...,
     {
       "name": "DD_APPSEC_ENABLED",
       "value": "true"
     }
   ]
   ```

      {% /tab %}

   {% tab title="AWS Fargate" %}
Add the following line to your container Dockerfile:

   ```Dockerfile
   ENV DD_APPSEC_ENABLED=true
   ```

      {% /tab %}

1. **Restart the application** using a full stop and start.

After this configuration is complete, the library collects security data from your application and sends it to the Agent. The Agent sends the data to Datadog, where [out-of-the-box detection rules](https://docs.datadoghq.com/security/default_rules/#cat-application-security) flag attacker techniques and potential misconfigurations so you can take steps to remediate.

1. To see App and API Protection threat detection in action, send known attack patterns to your application. For example, trigger the [Security Scanner Detected](https://docs.datadoghq.com/security/default_rules/security-scan-detected/) rule by running a file that contains the following curl script:

   ```
   for ((i=1;i<=250;i++)); do# Target existing service's routescurl https://your-application-url/existing-route -A dd-test-scanner-log;# Target non existing service's routescurl https://your-application-url/non-existing-route -A dd-test-scanner-log;done
```

**Note**: The `dd-test-scanner-log` value is supported in the most recent releases.

A few minutes after you enable your application and send known attack patterns to it, threat information appears in the [Application Signals Explorer](https://app.datadoghq.com/security/appsec) and vulnerability information appears in the [Vulnerabilities explorer](https://app.datadoghq.com/security/appsec/vm/).

{% video
   url="https://datadog-docs.imgix.net/images//security/application_security/appsec-getstarted-threat-and-vuln_2.mp4" /%}

## Using AAP without APM tracing{% #using-aap-without-apm-tracing %}

If you want to use Application & API Protection without APM tracing functionality, you can deploy with tracing disabled:

1. Configure your tracing library with the `DD_APM_TRACING_ENABLED=false` environment variable in addition to the `DD_APPSEC_ENABLED=true` environment variable.
1. This configuration will reduce the amount of APM data sent to Datadog to the minimum required by App and API Protection products.

For more details, see [Standalone App and API Protection][standalone_billing_guide]. [standalone_billing_guide]: /security/application_security/guide/standalone_application_security/

## 4. Verify setup

To verify that App and API Protection is working correctly:

1. Send some traffic to your application
1. Check the [Application Signals Explorer](https://app.datadoghq.com/security/appsec) in Datadog
1. Look for security signals and vulnerabilities

## Further Reading{% #further-reading %}

- [Adding user information to traces](https://docs.datadoghq.com/security/application_security/add-user-info/)
- [.NET Datadog library source code](https://github.com/DataDog/dd-trace-dotnet)
- [OOTB App and API Protection Rules](https://docs.datadoghq.com/security/default_rules/?category=cat-application-security)
- [Troubleshooting App and API Protection](https://docs.datadoghq.com/security/application_security/troubleshooting)
