The best way to install Raygun4Net.AspNetCore is to use use the dotnet cli tool. In your project folder run dotnet add package Mindscape.Raygun4Net.AspNetCore to install it.

Another method is to directly edit your .csproj file and add "Mindscape.Raygun4Net.AspNetCore": "6.6.6" to your dependencies. After you've done this, run dotnet.exe restore or restore packages within Visual Studio to download and install the package.

Alternatively, visit for instructions on installation.

Add the following code to your appsettings.json (if you're using another type of config, add it there):

"RaygunSettings": {
  "ApiKey": "YOUR_APP_API_KEY"

Your app API key is displayed when you create a new application in your Raygun account, or can be viewed in the application settings. RaygunSettings has many options which are explained further down this page.

Although it is not needed for Real User Monitoring we also recommend adding Raygun Crash reporting to your ASP.​Net backend code. Details on how to do this can be found here

In the /[Pages|Views]/Shared/_layout.cshtml file, on the first line, add @inject Microsoft.Extensions.Configuration.IConfiguration Configuration

The at the end of the <head/> section add the Raygun4js code with the API key automatically imported from the app configuration

@inject Microsoft.Extensions.Configuration.IConfiguration Configuration
<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - razorDemo</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
    <link rel="stylesheet" href="~/razorDemo.styles.css" asp-append-version="true" />
    <script type="text/javascript">
      h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({
    <script type="text/javascript">
      rg4js('apiKey', '@Configuration["RaygunSettings:ApiKey"]');
      rg4js('enableRUM', true);
      rg4js('enableCrashReporting', true); <!-- optional, enable CrashReporting -->
<!-- the rest of the body  -->

If you want to include the logged-in users details, they can populated from the HttpContext.User object

Add @using System.Security.Claims to the top of the _layout.cshtml file Then update the end of the <head> section to include the rg4js('setUser', {}); section below.

Depending on your authentication model, you may need to adjust what ClaimTypes you use.

<script type="text/javascript">
  rg4js('apiKey', '@Configuration["RaygunSettings:ApiKey"]');
  rg4js('enableCrashReporting', true);
  rg4js('enableRUM', true); <!-- optional enable RUM -->
  rg4js('setUser', {
        identifier: @ViewContext.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier),
        isAnonymous: @(!(ViewContext.HttpContext?.User?.Identity?.IsAuthenticated ??false)),
        email: @ViewContext.HttpContext?.User?.FindFirstValue(ClaimTypes.Email),
        fullName: @ViewContext.HttpContext?.User?.FindFirstValue(ClaimTypes.GivenName),

There are more configuration options for the javascript Raygun provider. See the javascript language guide for more details.

On this page: