中介軟體:資料庫錯誤頁面已標示為已過時

DatabaseErrorPageMiddleware 及其相關聯的擴充方法在 ASP.NET Core 5.0 中標示為已淘汰。 ASP.NET Core 6.0 中將會移除中介軟體和擴充方法。 此功能會改為由 DatabaseDeveloperPageExceptionFilter 及其擴充方法提供。

若要查看討論內容,請參閱 dotnet/aspnetcore#24987 上的 GitHub 問題。

導入的版本

5.0 RC 1

舊的行為

DatabaseErrorPageMiddleware 及其相關聯的擴充方法尚未淘汰。

新的行為

DatabaseErrorPageMiddleware 及其相關聯的擴充方法已淘汰。

變更原因

DatabaseErrorPageMiddleware 已遷移至開發人員例外狀況頁面的可延伸 API。 如需可延伸 API 的詳細資訊,請參閱 GitHub 問題 dotnet/aspnetcore#8536

完成下列步驟:

  1. 停止在您的專案中使用 DatabaseErrorPageMiddleware。 例如,從 Startup.Configure 移除 UseDatabaseErrorPage 方法呼叫:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDatabaseErrorPage();
        }
    }
    
  2. 將開發人員例外狀況頁面新增至您的專案。 例如,在 Startup.Configure 中呼叫 UseDeveloperExceptionPage 方法:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
    }
    
  3. Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore NuGet 套件新增至專案檔。

  4. 將資料庫開發人員頁面例外狀況篩選新增至服務集合。 例如,在 Startup.ConfigureServices 中呼叫 AddDatabaseDeveloperPageExceptionFilter 方法:

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

受影響的 API