Skip to main content
You are viewing help content for pre-release software. This document and the features it describes are subject to change.
All docs
V26.2
  • Process Dashboard Requests in the Blazor Circuit

    • 7 minutes to read

    The DxDashboard component can process client data requests in two ways:

    HTTP requests to a dashboard controller (default)
    The component sends HTTP requests to the dashboard controller registered using the MapDashboardRoute method. This mode is suitable for all render modes (Interactive Server and Interactive WebAssembly).
    Requests in the Blazor Circuit
    In the Interactive Server render mode, the component can process requests within the Blazor circuit instead. The Blazor circuit is the SignalR connection that the Blazor app uses to communicate with the server. In this mode, dashboard services run in the circuit’s dependency injection scope and can use the app’s scoped services (for example, to obtain information about the current user). This mode does not require a dashboard controller.

    When to Process Requests in the Blazor Circuit

    Process requests in the Blazor circuit if dashboard server-side code needs information that belongs to the current user’s Blazor session. For example:

    • The current user’s identity
    • User-specific connection strings or dashboard parameters
    • User-specific dashboard storage (multi-tenant applications)
    • Data filtered by the current user

    When the component sends HTTP requests to a dashboard controller, dashboard services cannot use the state of your application’s scoped services, such as the current user. When the component processes requests in the Blazor circuit, they can. For more information, refer to the following section: Access User-Specific Data.

    Compare Request Processing Modes

    The following table compares the two modes:

    Dashboard Controller (Default) Blazor Circuit
    Setup A dashboard controller, the MapDashboardRoute method call, and the Endpoint property. A method call: AddDevExpressBlazorDashboard.
    Render modes Interactive Server, Interactive WebAssembly Interactive Server only
    Dependency injection scope A separate scope for each HTTP request The scope of the user’s circuit
    Access to the app’s scoped services (for example, the current user) No Yes
    HttpContext, IHttpContextAccessor, session state Available Not available
    Custom request headers (RequestHttpHeaders) Supported Not applicable
    Restrict the client trust level Derive from RestrictedDashboardController or handle the VerifyClientTrustLevel event Set the WorkingMode property to ViewerOnly, call UseRestrictedClientTrustLevel, or handle the VerifyClientTrustLevel event

    For information on how to use a dashboard controller, refer to the following help topics:

    Get Started

    Follow the steps below to add a Dashboard component to a Blazor Server app and configure that component to process requests in the Blazor circuit.

    1. Create a new Blazor app named BlazorDashboardApp. Use one of the following options:

      If you use an existing Blazor Server application, skip this step.

    2. Install the following NuGet packages in your project:

      • DevExpress.AspNetCore.Dashboard
      • DevExpress.Blazor.Dashboard
    3. In the _Imports.razor file, add the DevExpress.DashboardBlazor and DevExpress.DashboardWeb namespaces:

      @using DevExpress.DashboardBlazor
      @using DevExpress.DashboardWeb
      
    4. In the application, create a Data/Dashboards folder to store dashboards.

    5. In the Program.cs file, register the DashboardConfigurator as a scoped service and call the AddDevExpressBlazorDashboard method. The following code snippet stores dashboards in the Data/Dashboards folder and registers a sample JSON data source:

      using DevExpress.DashboardBlazor;
      using DevExpress.DashboardCommon;
      using DevExpress.DashboardWeb;
      using DevExpress.DataAccess.Json;
      using Microsoft.Extensions.FileProviders;
      
      var builder = WebApplication.CreateBuilder(args);
      IFileProvider fileProvider = builder.Environment.ContentRootFileProvider;
      
      builder.Services.AddRazorComponents()
           .AddInteractiveServerComponents();
      
      builder.Services.AddScoped<DashboardConfigurator>((IServiceProvider serviceProvider) => {
           DashboardConfigurator configurator = new DashboardConfigurator();
           configurator.SetDashboardStorage(new DashboardFileStorage(fileProvider.GetFileInfo("Data/Dashboards").PhysicalPath));
           DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
           DashboardJsonDataSource jsonDataSourceUrl = new DashboardJsonDataSource("JSON Data Source (URL)");
           jsonDataSourceUrl.JsonSource = new UriJsonSource(
                new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"));
           jsonDataSourceUrl.RootElement = "Customers";
           dataSourceStorage.RegisterDataSource("jsonDataSourceUrl", jsonDataSourceUrl.SaveToXml());
           configurator.SetDataSourceStorage(dataSourceStorage);
           return configurator;
      });
      
      builder.Services.AddDevExpressBlazorDashboard();
      

      The AddDevExpressBlazorDashboard method applies to the entire application: all Dashboard components with the Interactive Server render mode process requests in the Blazor circuit.

    6. Reference the Dashboard stylesheets in the Components/App.razor file:

      <head>
      @* ... *@
          <link href="_content/DevExpress.Blazor.Dashboard/ace.css" rel="stylesheet" />
          <link href="_content/DevExpress.Blazor.Dashboard/ace-theme-dreamweaver.css" rel="stylesheet" />
          <link href="_content/DevExpress.Blazor.Dashboard/ace-theme-ambiance.css" rel="stylesheet" />
          <link href="_content/DevExpress.Blazor.Dashboard/dx.light.css" rel="stylesheet" />
          <link href="_content/DevExpress.Blazor.Dashboard/dx-analytics.common.css" rel="stylesheet" />
          <link href="_content/DevExpress.Blazor.Dashboard/dx-analytics.light.css" rel="stylesheet" />
          <link href="_content/DevExpress.Blazor.Dashboard/dx-querybuilder.css" rel="stylesheet" />
          <link href="_content/DevExpress.Blazor.Dashboard/dx-dashboard.light.min.css" rel="stylesheet" />
          @* ... *@
      </head>
      
    7. Add a Dashboard component to a page with the Interactive Server render mode:

      @page "/dashboard"
      @rendermode InteractiveServer
      
      <DxDashboard style="width: 100%; height: 800px;">
      </DxDashboard>
      
    8. In the Components/Layout/NavMenu.razor file, add a NavLink component to display the Dashboard item in the navigation menu:

      <div class="nav-item px-3">
          <NavLink class="nav-link" href="dashboard">
              <span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Dashboard
          </NavLink>
      </div>
      
    9. Run the application and open the page with the Dashboard component. The component opens in the Designer mode. You can now create a dashboard.

    Migrate from Dashboard Controller

    Follow the steps below to switch an existing Blazor Server app from a dashboard controller to request processing in the Blazor circuit:

    1. Call the AddDevExpressBlazorDashboard method in the Program.cs file.
    2. Make sure the page with the Dashboard component uses the Interactive Server render mode.
    3. Replace code that uses HttpContext, IHttpContextAccessor, or session state with scoped services.
    4. Replace RequestHttpHeaders with scoped services that store required values.
    5. If you use RestrictedDashboardController, call the UseRestrictedClientTrustLevel method instead.
    6. Remove the dashboard controller, the MapDashboardRoute method call, and the Endpoint property if your app no longer uses them.

    Security Considerations

    When the component processes requests in the Blazor circuit, it does not use dashboard controllers (including RestrictedDashboardController). The working mode determines the client trust level as follows:

    ViewerOnly working mode
    If the WorkingMode property is set to ViewerOnly, the default client trust level is Restricted: users cannot create, edit, or save dashboards on the server. Working mode changes on the client side do not affect the client trust level.
    Designer and Viewer working modes
    The default client trust level is Full, the same as for the DashboardController class.

    You can change the client trust level in the following ways:

    • Handle the VerifyClientTrustLevel event and set the e.ClientTrustLevel property. Use this event to specify access rights for individual users.
    • Call the UseRestrictedClientTrustLevel method to restrict the client trust level for all Dashboard components in the application:

      builder.Services.AddDevExpressBlazorDashboard(config => config.UseRestrictedClientTrustLevel());
      

      This method is the Blazor circuit equivalent of the RestrictedDashboardController class: the client trust level is always Restricted, and the DashboardConfigurator does not raise the VerifyClientTrustLevel event.

    Restricted mode affects the Web Dashboard in the following manner:

    • Only dashboards stored in dashboard storage can be processed on the client. Designer mode does not work.

    • Calling the IEditableDashboardStorage.AddDashboard and IDashboardStorage.SaveDashboard methods leads to an exception.

    • Information about data sources contained in a dashboard xml definition is not passed to the client when you request a dashboard XML file.

    Note

    The UseRestrictedClientTrustLevel method restricts operations on the server only. The method does not change the Dashboard component UI: in the Designer and Viewer working modes, users can still open the Designer, but Designer operations fail. Set the WorkingMode property to ViewerOnly to hide the Designer UI.

    You cannot combine the UseRestrictedClientTrustLevel and UseAspNetCoreControllers methods: the application throws an exception. To restrict the client trust level for ASP.NET Core controllers, derive your dashboard controller from RestrictedDashboardController or handle the VerifyClientTrustLevel event.

    For more information, refer to the following help topic: Security Considerations in ASP.NET Core.

    Access User-Specific Data

    When the Dashboard component processes requests in the Blazor circuit, dashboard services (such as the DashboardConfigurator, dashboard storage, or a connection string provider) can use the same scoped services as other parts of your Blazor application. For example, you can you can obtain information about the current user from a scoped service and load only this user’s dashboards or connection strings.

    Note

    HttpContext is not available in this mode. Code that uses IHttpContextAccessor or session state does not work.

    Message Size Limit

    SignalR limits incoming messages to 32 KB by default. Large requests (for example, saving a large dashboard) can exceed this limit. To increase it, use the MaximumReceiveMessageSize option:

    builder.Services.AddRazorComponents()
        .AddInteractiveServerComponents()
        .AddHubOptions(options => options.MaximumReceiveMessageSize = 64 * 1024);