Installation

Learn how to install the .NET Core Enforcer in your ASP.NET Core application.

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.

If your application uses classic ASP.NET on .NET Framework rather than ASP.NET Core, we recommend using HUMAN’s ASP.NET Enforcer 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 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 extention 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.
1

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:
dotnet add package HumanModule --version <VERSION>

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

  1. Restore and build the project:
dotnet restore
dotnet build
2

Add required HUMAN configurations

Next, add the required HUMAN configurations to your project. You can also add any optional configurations 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:
"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
}
3

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:
using human_module;
  1. Before builder.Build(), register the HUMAN configuration section:
builder.Services.Configure<EnforcerConfig>(builder.Configuration.GetSection("HumanConfiguration"));
  1. 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:
app.UseHumanMiddleware();

Your Program.cs should look similar to this:

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:

dotnet add package HumanModule --version <VERSION>