---
title: "ASP.NET"
description: "Learn about Sentry's .NET integration with ASP.NET."
url: https://docs.sentry.io/platforms/dotnet/guides/aspnet/
---

# ASP.NET | Sentry for ASP.NET

Sentry provides an integration with ASP.NET through the [Sentry.AspNet NuGet package](https://www.nuget.org/packages/Sentry.AspNet).

## [Features](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#features)

In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](https://docs.sentry.io/concepts/key-terms/tracing.md).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

## [Install](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#install)

Error Monitoring\[ ]Tracing

Add the Sentry dependency:

```powershell
Install-Package Sentry.AspNet -Version 6.3.2
```

You can combine this integration with a logging library like `log4net`, `NLog` or `Serilog` to include both request data as well as your logs as breadcrumbs. The logging integrations also capture events when an error is logged.

## [Configure](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#configure)

You configure the SDK in the `Global.asax.cs`:

```csharp
using System;
using System.Web;
using Sentry.AspNet;
using Sentry.EntityFramework; // If you also installed Sentry.EntityFramework
using Sentry.Extensibility;

public class MvcApplication : HttpApplication
{
    private IDisposable _sentry;

    protected void Application_Start()
    {
        // Initialize Sentry to capture AppDomain unhandled exceptions and more.
        _sentry = SentrySdk.Init(options =>
        {
            options.Dsn = "___PUBLIC_DSN___";
            // When configuring for the first time, to see what the SDK is doing:
            options.Debug = true;
            // Adds request URL and headers, IP and name for users, etc.
            options.SendDefaultPii = true;

            // ___PRODUCT_OPTION_START___ performance
            // Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
            // We recommend adjusting this value in production.
            options.TracesSampleRate = 1.0;
            // ___PRODUCT_OPTION_END___ performance

            // If you also installed the Sentry.EntityFramework package
            options.AddEntityFramework();
            options.AddAspNet();
        });
    }

    // Global error catcher
    protected void Application_Error() => Server.CaptureLastError();

    // ___PRODUCT_OPTION_START___ performance
    protected void Application_BeginRequest()
    {
        Context.StartSentryTransaction();
    }

    protected void Application_EndRequest()
    {
        Context.FinishSentryTransaction();
    }
    // ___PRODUCT_OPTION_END___ performance

    protected void Application_End()
    {
        // Flushes out events before shutting down.
        _sentry?.Dispose();
    }
}
```

### [Capturing the affected user](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#capturing-the-affected-user)

When opting-in to [SendDefaultPii](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#senddefaultpii), the SDK will automatically read the user from the request by inspecting `HttpContext.User`. Default claim values like `NameIdentifier` for the *Id* will be used.

```csharp
options.AddAspNet();
options.Dsn = "___PUBLIC_DSN___";
// Opt-in to send things like UserId and UserName if a user is logged-in
options.SendDefaultPii = true;
```

### [SendDefaultPii](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#senddefaultpii)

Although this setting is part of the [Sentry](https://docs.sentry.io/platforms/dotnet.md) package, in the context of ASP.NET Core, it means reporting the user by reading the frameworks `HttpContext.User`. The strategy to create the `SentryUser` can be customized.

### [IncludeRequestPayload](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#includerequestpayload)

It's helpful to troubleshoot a problem in the API when the payload that hit the endpoint is logged. Opt-in to send the request body to Sentry:

```csharp
options.AddAspNet(RequestSize.Always);
```

## [Verify](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#verify)

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

```csharp
try
{
    throw null;
}
catch (Exception ex)
{
    SentrySdk.CaptureException(ex);
}
```

## [Troubleshooting](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#troubleshooting)

For information about Troubleshooting, please visit the [troubleshooting](https://docs.sentry.io/platforms/dotnet/guides/aspnet/troubleshooting.md) page.

## [Samples](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#samples)

* A [sample with ASP.NET and EF 6](https://github.com/getsentry/examples/tree/master/dotnet/AspNetMvc5Ef6) and additional samples of the [.NET SDKs](https://github.com/getsentry/examples/tree/master/dotnet)

## [Next Steps](https://docs.sentry.io/platforms/dotnet/guides/aspnet.md#next-steps)

* Explore [practical guides](https://docs.sentry.io/guides.md) on what to monitor, log, track, and investigate after setup

## Other .NET Frameworks

- [.NET for Android](https://docs.sentry.io/platforms/dotnet/guides/android.md)
- [.NET for iOS, macOS, and Mac Catalyst](https://docs.sentry.io/platforms/dotnet/guides/apple.md)
- [ASP.NET Core](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore.md)
- [AWS Lambda](https://docs.sentry.io/platforms/dotnet/guides/aws-lambda.md)
- [Azure Functions](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker.md)
- [Blazor Interactive SSR](https://docs.sentry.io/platforms/dotnet/guides/blazor-server.md)
- [Blazor WebAssembly](https://docs.sentry.io/platforms/dotnet/guides/blazor-webassembly.md)
- [Entity Framework](https://docs.sentry.io/platforms/dotnet/guides/entityframework.md)
- [Google Cloud Functions](https://docs.sentry.io/platforms/dotnet/guides/google-cloud-functions.md)
- [log4net](https://docs.sentry.io/platforms/dotnet/guides/log4net.md)
- [MAUI](https://docs.sentry.io/platforms/dotnet/guides/maui.md)
- [Microsoft.Extensions.Logging](https://docs.sentry.io/platforms/dotnet/guides/extensions-logging.md)
- [NLog](https://docs.sentry.io/platforms/dotnet/guides/nlog.md)
- [Serilog](https://docs.sentry.io/platforms/dotnet/guides/serilog.md)
- [Windows Forms](https://docs.sentry.io/platforms/dotnet/guides/winforms.md)
- [WinUI](https://docs.sentry.io/platforms/dotnet/guides/winui.md)
- [WPF](https://docs.sentry.io/platforms/dotnet/guides/wpf.md)
- [Xamarin](https://docs.sentry.io/platforms/dotnet/guides/xamarin.md)

## Topics

- [Capturing Errors](https://docs.sentry.io/platforms/dotnet/guides/aspnet/usage.md)
- [Enriching Events](https://docs.sentry.io/platforms/dotnet/guides/aspnet/enriching-events.md)
- [Extended Configuration](https://docs.sentry.io/platforms/dotnet/guides/aspnet/configuration.md)
- [Logs](https://docs.sentry.io/platforms/dotnet/guides/aspnet/logs.md)
- [Data Management](https://docs.sentry.io/platforms/dotnet/guides/aspnet/data-management.md)
- [Tracing](https://docs.sentry.io/platforms/dotnet/guides/aspnet/tracing.md)
- [Security Policy Reporting](https://docs.sentry.io/platforms/dotnet/guides/aspnet/security-policy-reporting.md)
- [Crons](https://docs.sentry.io/platforms/dotnet/guides/aspnet/crons.md)
- [Migration Guide](https://docs.sentry.io/platforms/dotnet/guides/aspnet/migration.md)
- [User Feedback](https://docs.sentry.io/platforms/dotnet/guides/aspnet/user-feedback.md)
- [Metrics](https://docs.sentry.io/platforms/dotnet/guides/aspnet/metrics.md)
- [Unit Testing](https://docs.sentry.io/platforms/dotnet/guides/aspnet/unit-testing.md)
- [Legacy SDK](https://docs.sentry.io/platforms/dotnet/guides/aspnet/legacy-sdk.md)
- [Troubleshooting](https://docs.sentry.io/platforms/dotnet/guides/aspnet/troubleshooting.md)
