> This page is for Applications Protection.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.humansecurity.com/llms.txt.

# Installation

If your organization uses **ASP.NET Core,** you can use HUMAN’s **.NET Core Enforcer** to protect your application from malicious behavior. The Enforcer is installed as a NuGet package in an existing ASP.NET Core application and runs as middleware in the application’s request pipeline. It evaluates incoming requests and applies the handling configured for your HUMAN application.

> **Note**
>
> If your application uses classic ASP.NET on .NET Framework rather than ASP.NET Core, we recommend using HUMAN’s [ASP.NET Enforcer](/applications/aspnet) instead.

You can learn how to install the .NET Core Enforcer with this article.

## Prerequisites

* .NET version 6.0 or higher. See [Microsoft's documentation](https://learn.microsoft.com/en-us/dotnet/core/install/) for installation instructions.
* An existing ASP.NET Core project with a `.csproj` file. You'll add HUMAN's Enforcer as a NuGet middleware to this project.
* (Optional) Visual Studio Code, where you can install the HUMAN Module extension with the NuGet package manager.
* Your unique HUMAN information:
  * Your **Application ID.** You can find this under **Platform Settings > Applications > Select an application > Application Settings > Application ID** in the HUMAN console. If you have multiple environments, you will also have multiple Application IDs, so be sure to choose the correct ID for the environment you want to install on.
  * Your **Server Token.** You can find this under **Platform Settings > Applications > Select an application > Application Settings > Server Token.**
  * Your **Risk Cookie Key.** You can find this under **Bot Defender > Policies > Policy Settings > Policy Information.**

## Install the HUMAN package

1. In the CLI, navigate to the directory of your ASP.NET Core project that has the `.csproj` file.
2. Run the following command. Replace `<VERSION>` with the latest version from the [changelog](/applications/net-core/changelog):

```bash
dotnet add package HumanModule --version <VERSION>
```

> **Note**
>
> Alternatively, in Visual Studio Code, you can select **Project > Manage NuGet Packages**, search for **HumanModule**, and install it.

3. Restore and build the project:

```bash
dotnet restore
dotnet build
```

## Add required HUMAN configurations

Next, add the required HUMAN configurations to your project. You can also add any [optional configurations](/applications/net-core/configuration) in this step.

1. Open your project's JSON configuration file. This is named `appsettings.json` by default.
2. Add a `HumanConfiguration` section to the root of the file, and update the fields with your **Application ID**, **Risk Cookie Key**, and **Server Token** respectively:

```json
"HumanConfiguration": {
    "px_app_id": "<APPLICATION_ID>", // In the form PX12345678
    "px_cookie_secret": "<RISK_COOKIE_KEY>",
    "px_auth_token": "<SERVER_TOKEN>"
    // Other HUMAN optional configurations can be added here as well
}
```

## Update Program.cs

Finally, update your project's `Program.cs` file to register HUMAN configuration and add the Enforcer middleware.

1. Navigate to your project's `Program.cs` file.
2. Add the following `using` statement:

```c# showLineNumbers={false}
using human_module;
```

3. Before `builder.Build()`, register the HUMAN configuration section:

```c# showLineNumbers={false}
builder.Services.Configure<EnforcerConfig>(builder.Configuration.GetSection("HumanConfiguration"));
```

4. After building the app, add `UseHumanMiddleware()` to the request pipeline. Place it after general request-processing middleware (for example, HTTPS redirection, static files, and routing) and before your application endpoints:

```c# showLineNumbers={false}
app.UseHumanMiddleware();
```

Your `Program.cs` should look similar to this:

**`Program.cs`**

```c# Program.cs
using human_module;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages(); // or AddControllers(), etc.

builder.Services.Configure<EnforcerConfig>(builder.Configuration.GetSection("HumanConfiguration"));

// Optional: use IHttpClientFactory to manage HTTP client lifetimes
// builder.Services.AddHttpClient();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();

app.UseHumanMiddleware();

app.MapRazorPages(); // or MapControllers(), etc.

app.Run();
```

## Upgrading

To upgrade to the latest Enforcer version:

1. In Visual Studio, right-click the solution and select **Manage NuGet Packages for Solution**.
2. Search for `HumanModule` in the **Updates** section, and update.

Or from the CLI:

```bash
dotnet add package HumanModule --version <VERSION>
```