Middleware: Database error page marked as obsolete

The DatabaseErrorPageMiddleware and its associated extension methods were marked as obsolete in ASP.NET Core 5.0. The middleware and extension methods will be removed in ASP.NET Core 6.0. The functionality will instead be provided by DatabaseDeveloperPageExceptionFilter and its extension methods.

For discussion, see the GitHub issue at dotnet/aspnetcore#24987.

Version introduced

5.0 RC 1

Old behavior

DatabaseErrorPageMiddleware and its associated extension methods weren't obsolete.

New behavior

DatabaseErrorPageMiddleware and its associated extension methods are obsolete.

Reason for change

DatabaseErrorPageMiddleware was migrated to an extensible API for the developer exception page. For more information on the extensible API, see GitHub issue dotnet/aspnetcore#8536.

Complete the following steps:

  1. Stop using DatabaseErrorPageMiddleware in your project. For example, remove the UseDatabaseErrorPage method call from Startup.Configure:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDatabaseErrorPage();
        }
    }
    
  2. Add the developer exception page to your project. For example, call the UseDeveloperExceptionPage method in Startup.Configure:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
    }
    
  3. Add the Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore NuGet package to the project file.

  4. Add the database developer page exception filter to the services collection. For example, call the AddDatabaseDeveloperPageExceptionFilter method in Startup.ConfigureServices:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDatabaseDeveloperPageExceptionFilter();
    }
    

Affected APIs