Indiko.Hosting.BlazorServer 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Indiko.Hosting.BlazorServer --version 2.1.0
                    
NuGet\Install-Package Indiko.Hosting.BlazorServer -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Indiko.Hosting.BlazorServer" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Indiko.Hosting.BlazorServer" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Indiko.Hosting.BlazorServer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Indiko.Hosting.BlazorServer --version 2.1.0
                    
#r "nuget: Indiko.Hosting.BlazorServer, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Indiko.Hosting.BlazorServer@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Indiko.Hosting.BlazorServer&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Indiko.Hosting.BlazorServer&version=2.1.0
                    
Install as a Cake Tool

Indiko.Hosting.BlazorServer

Blazor Server application hosting implementation for building interactive web applications with the Indiko framework.

Overview

This package provides a complete hosting solution for Blazor Server applications, including OpenID Connect authentication, security headers, CORS configuration, and seamless integration with Indiko Blocks.

Features

  • Blazor Server Hosting: Full Blazor Server support with SignalR hubs
  • OpenID Connect Authentication: Built-in OIDC/OAuth2 authentication support
  • Security Headers: CSP and other security headers for enhanced protection
  • Cookie Authentication: Secure cookie-based session management
  • Authorization Policies: Configurable authorization for pages and components
  • PKCE Support: Proof Key for Code Exchange for enhanced security
  • Static File Serving: wwwroot static file support
  • HTTPS Support: Optional HTTPS redirection and HSTS
  • Forwarded Headers: Support for reverse proxy scenarios
  • Razor Pages: Full Razor Pages support alongside Blazor components

Installation

dotnet add package Indiko.Hosting.BlazorServer

Quick Start

Minimal Setup

using Indiko.Hosting.BlazorServer;

// Create your startup class
public class Startup : BlazorServerStartup
{
    public Startup(IConfiguration configuration, IWebHostEnvironment environment)
        : base(configuration, environment)
    {
    }

    protected override bool AddControllersWithViews => false;
    protected override bool EnableForwardedHeaderOptions => false;
    protected override bool ForceHttps => true;
    protected override bool AddSecurityHeaderSupport => true;
    protected override bool AddOpenIdConfiguration => true; // Enable auth
    protected override bool AddAuthentication => true;

    public override void ConfigureServices(IServiceCollection services)
    {
        base.ConfigureServices(services);
        
        // Add your services
        services.AddScoped<IMyService, MyService>();
    }
}

// Program.cs
class Program
{
    static async Task<int> Main(string[] args)
    {
        return await BlazorServerHostBootstrapper.Instance.RunAsync<Startup>(args);
    }
}

Configuration (appsettings.json)

{
  "OpenIDConnectSettings": {
    "Authority": "https://your-identity-server.com",
    "ClientId": "blazor-app",
    "ClientSecret": "your-client-secret"
  }
}

Key Components

BlazorServerHostBootstrapper

Singleton bootstrapper for Blazor Server applications.

await BlazorServerHostBootstrapper.Instance.RunAsync<Startup>(args);

BlazorServerStartup

Abstract base class with configurable Blazor Server features.

public class MyStartup : BlazorServerStartup
{
    protected override bool AddAuthentication => true;
    protected override bool AddOpenIdConfiguration => true;
    protected override bool AddSecurityHeaderSupport => true;
    protected override bool ForceHttps => true;
}

OpenIDConnectSettings

Configuration model for OpenID Connect authentication.

public class OpenIDConnectSettings
{
    public string Authority { get; set; }
    public string ClientId { get; set; }
    public string ClientSecret { get; set; }
}

Authentication & Authorization

OpenID Connect Setup

Enable authentication in your startup:

protected override bool AddAuthentication => true;
protected override bool AddOpenIdConfiguration => true;

Configure in appsettings.json:

{
  "OpenIDConnectSettings": {
    "Authority": "https://identity.example.com",
    "ClientId": "my-blazor-app",
    "ClientSecret": "secret",
    "Scopes": ["openid", "profile", "email"]
  }
}

Authorization in Components

@page "/"
@attribute [Authorize]

<h1>Hello, @context.User.Identity.Name!</h1>

<AuthorizeView>
    <Authorized>
        <p>You are logged in as @context.User.Identity.Name</p>
    </Authorized>
    <NotAuthorized>
        <p>You need to log in.</p>
    </NotAuthorized>
</AuthorizeView>

Require Authentication Globally

When authentication is enabled, all Razor Pages require authentication by default:

// This is configured automatically when AddAuthentication = true
services.AddRazorPages().AddMvcOptions(options =>
{
    var policy = new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .Build();
    options.Filters.Add(new AuthorizeFilter(policy));
});

Security Headers

Enable security headers for enhanced protection:

protected override bool AddSecurityHeaderSupport => true;

This configures:

  • Content Security Policy (CSP)
  • X-Frame-Options
  • X-Content-Type-Options
  • Referrer-Policy
  • Permissions-Policy

Headers are automatically adjusted based on:

  • Environment (Development vs Production)
  • OpenID Connect Authority (for CSP)

Features in Detail

Blazor Components

@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }
}

Service Injection

@inject IMyService MyService

<h1>@MyService.GetMessage()</h1>

SignalR Hub Configuration

Blazor Server uses SignalR. The hub is automatically configured:

// When authentication is enabled
endpoints.MapBlazorHub().RequireAuthorization();

// Without authentication
endpoints.MapBlazorHub();

When OpenID Connect is enabled, cookie authentication is configured automatically:

options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;

Token Management

Tokens are automatically saved and can be accessed:

@inject IHttpContextAccessor HttpContextAccessor

@code {
    private async Task<string> GetAccessToken()
    {
        var context = HttpContextAccessor.HttpContext;
        return await context.GetTokenAsync("access_token");
    }
}

Project Structure

MyBlazorApp/
??? Pages/
?   ??? _Host.cshtml
?   ??? Index.razor
?   ??? Counter.razor
??? Shared/
?   ??? MainLayout.razor
?   ??? NavMenu.razor
??? wwwroot/
?   ??? css/
?   ??? js/
??? appsettings.json
??? Program.cs

CORS Configuration

Development Environment:

  • Allows any origin, method, and header (permissive for testing)

Production Environment:

  • CORS is not configured by default
  • Add custom CORS configuration if needed

Environment-Specific Behavior

Development

  • Developer exception page with detailed errors
  • Permissive CORS
  • Security headers (if enabled)
  • Forwarded headers (if enabled)

Production

  • HSTS enabled
  • HTTPS redirection (if enabled)
  • Security headers (if enabled)
  • Forwarded headers (if enabled)

Advanced Configuration

Custom Authorization Policies

public override void ConfigureServices(IServiceCollection services)
{
    base.ConfigureServices(services);
    
    services.AddAuthorization(options =>
    {
        options.AddPolicy("AdminOnly", policy =>
            policy.RequireClaim("role", "admin"));
    });
}

Custom Security Headers

Override or extend security headers:

protected override bool AddSecurityHeaderSupport => true;

// Security headers are configured via SecurityHeadersDefinitions
// which integrates with NetEscapades.AspNetCore.SecurityHeaders

Target Framework

  • .NET 10

Dependencies

  • Indiko.Hosting.Abstractions
  • Indiko.Blocks.Common.Abstractions
  • Indiko.Blocks.Common.Management
  • Microsoft.AspNetCore.App
  • Microsoft.AspNetCore.Authentication.OpenIdConnect
  • NetEscapades.AspNetCore.SecurityHeaders

License

See LICENSE file in the repository root.

  • Indiko.Hosting.Abstractions - Core hosting abstractions
  • Indiko.Hosting.Web - Web API hosting
  • Indiko.Hosting.Mvc - MVC hosting
  • Indiko.Blocks.Security.Authentication.ASPNetCore - Additional authentication features
  • Indiko.Blocks.Security.AuthenticationProvider.Blazor - Blazor authentication providers
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.1 25 12/2/2025
2.1.0 27 12/2/2025
2.0.0 267 9/17/2025
1.7.23 290 9/8/2025
1.7.22 156 9/8/2025
1.7.21 182 8/14/2025
1.7.20 222 6/23/2025
1.7.19 211 6/3/2025
1.7.18 215 5/29/2025
1.7.17 190 5/26/2025
1.7.15 163 4/12/2025
1.7.14 114 4/11/2025
1.7.13 133 3/29/2025
1.7.12 146 3/28/2025
1.7.11 157 3/28/2025
1.7.10 135 3/28/2025
1.7.9 125 3/28/2025
1.7.8 137 3/28/2025
1.7.5 166 3/17/2025
1.7.4 145 3/16/2025
1.7.3 157 3/16/2025
1.7.2 145 3/16/2025
1.7.1 175 3/11/2025
1.6.8 163 3/11/2025
1.6.7 210 3/4/2025
1.6.6 112 2/26/2025
1.6.5 107 2/20/2025
1.6.4 96 2/20/2025
1.6.3 111 2/5/2025
1.6.2 131 1/24/2025
1.6.1 117 1/24/2025
1.6.0 90 1/16/2025
1.5.2 83 1/16/2025
1.5.1 143 11/3/2024
1.5.0 96 10/26/2024
1.3.2 105 10/24/2024
1.3.0 158 10/10/2024
1.2.5 175 10/9/2024
1.2.4 184 10/8/2024
1.2.1 145 10/3/2024
1.2.0 156 9/29/2024
1.1.1 178 9/23/2024
1.1.0 169 9/18/2024
1.0.33 210 9/15/2024
1.0.28 187 8/28/2024
1.0.27 189 8/24/2024
1.0.26 183 7/7/2024
1.0.25 201 7/6/2024
1.0.24 158 6/25/2024
1.0.23 197 6/1/2024
1.0.22 202 5/14/2024
1.0.21 173 5/14/2024
1.0.20 193 4/8/2024
1.0.19 181 4/3/2024
1.0.18 201 3/23/2024
1.0.17 212 3/19/2024
1.0.16 227 3/19/2024
1.0.15 214 3/11/2024
1.0.14 206 3/10/2024
1.0.13 204 3/6/2024
1.0.12 231 3/1/2024
1.0.11 198 3/1/2024
1.0.10 219 3/1/2024
1.0.9 201 3/1/2024
1.0.8 202 2/19/2024
1.0.7 181 2/17/2024
1.0.6 201 2/17/2024
1.0.5 206 2/17/2024
1.0.4 192 2/7/2024
1.0.3 181 2/6/2024
1.0.1 220 2/6/2024
1.0.0 231 1/9/2024
1.0.0-preview99 236 12/22/2023
1.0.0-preview98 160 12/21/2023
1.0.0-preview97 174 12/21/2023
1.0.0-preview96 181 12/20/2023
1.0.0-preview95 174 12/20/2023
1.0.0-preview94 161 12/18/2023
1.0.0-preview93 213 12/13/2023
1.0.0-preview92 188 12/13/2023
1.0.0-preview91 188 12/12/2023
1.0.0-preview90 195 12/11/2023
1.0.0-preview89 194 12/11/2023
1.0.0-preview88 204 12/6/2023
1.0.0-preview87 195 12/6/2023
1.0.0-preview86 165 12/6/2023
1.0.0-preview85 157 12/6/2023
1.0.0-preview84 161 12/5/2023
1.0.0-preview83 169 12/5/2023
1.0.0-preview82 175 12/5/2023
1.0.0-preview81 191 12/4/2023
1.0.0-preview80 185 12/1/2023
1.0.0-preview77 160 12/1/2023
1.0.0-preview76 201 12/1/2023
1.0.0-preview75 181 12/1/2023
1.0.0-preview74 186 11/26/2023
1.0.0-preview73 187 11/7/2023
1.0.0-preview72 187 11/6/2023
1.0.0-preview71 184 11/3/2023
1.0.0-preview70 169 11/2/2023
1.0.0-preview69 175 11/2/2023
1.0.0-preview68 171 11/2/2023
1.0.0-preview67 168 11/2/2023
1.0.0-preview66 170 11/2/2023
1.0.0-preview65 176 11/2/2023
1.0.0-preview64 162 11/2/2023
1.0.0-preview63 194 11/2/2023
1.0.0-preview62 198 11/1/2023
1.0.0-preview61 182 11/1/2023
1.0.0-preview60 159 11/1/2023
1.0.0-preview59 208 11/1/2023
1.0.0-preview58 167 10/31/2023
1.0.0-preview57 181 10/31/2023
1.0.0-preview56 180 10/31/2023
1.0.0-preview55 188 10/31/2023
1.0.0-preview54 153 10/31/2023
1.0.0-preview53 168 10/31/2023
1.0.0-preview52 157 10/31/2023
1.0.0-preview51 176 10/31/2023
1.0.0-preview50 172 10/31/2023
1.0.0-preview48 158 10/31/2023
1.0.0-preview46 143 10/31/2023
1.0.0-preview45 167 10/31/2023
1.0.0-preview44 163 10/31/2023
1.0.0-preview43 177 10/31/2023
1.0.0-preview42 201 10/30/2023
1.0.0-preview41 150 10/30/2023
1.0.0-preview40 168 10/27/2023
1.0.0-preview39 192 10/27/2023
1.0.0-preview38 189 10/27/2023
1.0.0-preview37 162 10/27/2023
1.0.0-preview36 172 10/27/2023
1.0.0-preview35 178 10/27/2023
1.0.0-preview34 172 10/27/2023
1.0.0-preview33 182 10/26/2023
1.0.0-preview32 171 10/26/2023
1.0.0-preview31 162 10/26/2023
1.0.0-preview30 180 10/26/2023
1.0.0-preview29 216 10/26/2023
1.0.0-preview28 201 10/26/2023
1.0.0-preview27 190 10/26/2023
1.0.0-preview26 190 10/25/2023
1.0.0-preview25 191 10/23/2023
1.0.0-preview24 182 10/23/2023
1.0.0-preview23 185 10/23/2023
1.0.0-preview22 162 10/23/2023
1.0.0-preview21 193 10/23/2023
1.0.0-preview20 200 10/20/2023
1.0.0-preview19 165 10/19/2023
1.0.0-preview18 216 10/18/2023
1.0.0-preview16 235 10/11/2023
1.0.0-preview101 173 1/5/2024