[]
        
(Showing Draft Content)

ASP.NET Core のミドルウェア

JSビューワはサーバーサイドでレポートを描画します。

このトピックではレポートの描画処理を担当するミドルウェアの構成方法を説明します。


JSビューワとミドルウェア

  1. Visual Studio 2026 を開き、[ASP.NET Core Webアプリ]のテンプレートからプロジェクトを作成します。

    Create a New Project dialog

  2. プロジェクト名を入力し、[次へ]をクリックします。

    Create a New Project dialog

  3. ターゲットフレームワークに「.NET 8.0」を選択し、「HTTPS用の構成」オプションを無効にし、[作成]をクリックします。

    Create a new ASP.Net Core Web Application dialog

  4. ソリューションエクスプローラー]で、ソリューションを右クリックし、[NuGet パッケージの管理]を選択します。

  5. 以下のパッケージをプロジェクトにインストールします。

    • MESCIUS.ActiveReports.Aspnetcore.Viewer.ja

  6. プロジェクトフォルダ内に[Reports]フォルダを作成します。Reportsフォルダにはビューワに表示するレポートを配置します。

  7. レポートファイルの[ビルドアクション]プロパティを「埋め込みリソース」に変更します。

  8. Program.csを開き、app.UseReportViewerを実行するコードを追加します。

    using GrapeCity.ActiveReports.Aspnetcore.Viewer;
    var builder = WebApplication.CreateBuilder(args);
    // Add services to the container.
    builder.Services.AddRazorPages();
    var app = builder.Build();
    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
    }
    app.UseStaticFiles();
    // ActiveReports APIとハンドラのミドルウェアを設定します。
    app.UseReportViewer(settings =>
    {
        // ここでレポートの参照方法などを設定できます。
    });
    app.UseRouting();
    app.UseAuthorization();
    app.MapRazorPages();
    app.Run();
  9. レポートの参照方法に応じたコードをapp.UseReportViewerの内部に追加します。

    var entryAssembly = System.Reflection.Assembly.GetEntryAssembly();
    var reportsNamespace = "[プロジェクトの名前空間].Reports";
    // プロジェクトの埋め込みリソースを参照する場合
    settings.UseEmbeddedTemplates(reportsNamespace, entryAssembly);
    // サーバーのファイルシステムを参照する場合
    settings.UseFileStore(new System.IO.DirectoryInfo("C:\\Reports"));
    // コード形式セクションレポートを使用する場合
    settings.UseCodeBasedSectionReports(entryAssembly, reportsNamespace);

    メモ:同じメソッドを複数回実行した場合、最後の設定で上書きされます。