Indiko.Hosting.BlazorServer 2.1.2

dotnet add package Indiko.Hosting.BlazorServer --version 2.1.2
                    
NuGet\Install-Package Indiko.Hosting.BlazorServer -Version 2.1.2
                    
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.2" />
                    
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.2" />
                    
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.2
                    
#r "nuget: Indiko.Hosting.BlazorServer, 2.1.2"
                    
#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.2
                    
#: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.2
                    
Install as a Cake Addin
#tool nuget:?package=Indiko.Hosting.BlazorServer&version=2.1.2
                    
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.2 291 12/18/2025
2.1.1 686 12/2/2025
2.1.0 669 12/2/2025
2.0.0 288 9/17/2025
1.7.23 308 9/8/2025
1.7.22 172 9/8/2025
1.7.21 202 8/14/2025
1.7.20 246 6/23/2025
1.7.19 225 6/3/2025
1.7.18 241 5/29/2025
1.7.17 207 5/26/2025
1.7.15 179 4/12/2025
1.7.14 132 4/11/2025
1.7.13 158 3/29/2025
1.7.12 161 3/28/2025
1.7.11 171 3/28/2025
1.7.10 147 3/28/2025
1.7.9 139 3/28/2025
1.7.8 145 3/28/2025
1.7.5 188 3/17/2025
1.7.4 164 3/16/2025
1.7.3 177 3/16/2025
1.7.2 158 3/16/2025
1.7.1 187 3/11/2025
1.6.8 187 3/11/2025
1.6.7 230 3/4/2025
1.6.6 129 2/26/2025
1.6.5 117 2/20/2025
1.6.4 114 2/20/2025
1.6.3 133 2/5/2025
1.6.2 153 1/24/2025
1.6.1 139 1/24/2025
1.6.0 108 1/16/2025
1.5.2 99 1/16/2025
1.5.1 159 11/3/2024
1.5.0 116 10/26/2024
1.3.2 120 10/24/2024
1.3.0 169 10/10/2024
1.2.5 197 10/9/2024
1.2.4 207 10/8/2024
1.2.1 162 10/3/2024
1.2.0 170 9/29/2024
1.1.1 190 9/23/2024
1.1.0 185 9/18/2024
1.0.33 224 9/15/2024
1.0.28 207 8/28/2024
1.0.27 204 8/24/2024
1.0.26 198 7/7/2024
1.0.25 214 7/6/2024
1.0.24 173 6/25/2024
1.0.23 213 6/1/2024
1.0.22 218 5/14/2024
1.0.21 189 5/14/2024
1.0.20 213 4/8/2024
1.0.19 204 4/3/2024
1.0.18 215 3/23/2024
1.0.17 227 3/19/2024
1.0.16 246 3/19/2024
1.0.15 229 3/11/2024
1.0.14 222 3/10/2024
1.0.13 220 3/6/2024
1.0.12 240 3/1/2024
1.0.11 210 3/1/2024
1.0.10 234 3/1/2024
1.0.9 212 3/1/2024
1.0.8 215 2/19/2024
1.0.7 198 2/17/2024
1.0.6 221 2/17/2024
1.0.5 225 2/17/2024
1.0.4 211 2/7/2024
1.0.3 192 2/6/2024
1.0.1 241 2/6/2024
1.0.0 250 1/9/2024
1.0.0-preview99 247 12/22/2023
1.0.0-preview98 183 12/21/2023
1.0.0-preview97 187 12/21/2023
1.0.0-preview96 199 12/20/2023
1.0.0-preview95 186 12/20/2023
1.0.0-preview94 179 12/18/2023
1.0.0-preview93 223 12/13/2023
1.0.0-preview92 199 12/13/2023
1.0.0-preview91 203 12/12/2023
1.0.0-preview90 216 12/11/2023
1.0.0-preview89 207 12/11/2023
1.0.0-preview88 224 12/6/2023
1.0.0-preview87 212 12/6/2023
1.0.0-preview86 182 12/6/2023
1.0.0-preview85 171 12/6/2023
1.0.0-preview84 172 12/5/2023
1.0.0-preview83 186 12/5/2023
1.0.0-preview82 191 12/5/2023
1.0.0-preview81 211 12/4/2023
1.0.0-preview80 200 12/1/2023
1.0.0-preview77 172 12/1/2023
1.0.0-preview76 213 12/1/2023
1.0.0-preview75 194 12/1/2023
1.0.0-preview74 201 11/26/2023
1.0.0-preview73 199 11/7/2023
1.0.0-preview72 197 11/6/2023
1.0.0-preview71 199 11/3/2023
1.0.0-preview70 186 11/2/2023
1.0.0-preview69 186 11/2/2023
1.0.0-preview68 179 11/2/2023
1.0.0-preview67 172 11/2/2023
1.0.0-preview66 184 11/2/2023
1.0.0-preview65 192 11/2/2023
1.0.0-preview64 172 11/2/2023
1.0.0-preview63 205 11/2/2023
1.0.0-preview62 212 11/1/2023
1.0.0-preview61 197 11/1/2023
1.0.0-preview60 172 11/1/2023
1.0.0-preview59 230 11/1/2023
1.0.0-preview58 183 10/31/2023
1.0.0-preview57 198 10/31/2023
1.0.0-preview56 196 10/31/2023
1.0.0-preview55 203 10/31/2023
1.0.0-preview54 163 10/31/2023
1.0.0-preview53 180 10/31/2023
1.0.0-preview52 171 10/31/2023
1.0.0-preview51 188 10/31/2023
1.0.0-preview50 184 10/31/2023
1.0.0-preview48 168 10/31/2023
1.0.0-preview46 159 10/31/2023
1.0.0-preview45 186 10/31/2023
1.0.0-preview44 175 10/31/2023
1.0.0-preview43 193 10/31/2023
1.0.0-preview42 219 10/30/2023
1.0.0-preview41 158 10/30/2023
1.0.0-preview40 185 10/27/2023
1.0.0-preview39 203 10/27/2023
1.0.0-preview38 202 10/27/2023
1.0.0-preview37 175 10/27/2023
1.0.0-preview36 185 10/27/2023
1.0.0-preview35 193 10/27/2023
1.0.0-preview34 191 10/27/2023
1.0.0-preview33 197 10/26/2023
1.0.0-preview32 186 10/26/2023
1.0.0-preview31 167 10/26/2023
1.0.0-preview30 195 10/26/2023
1.0.0-preview29 229 10/26/2023
1.0.0-preview28 220 10/26/2023
1.0.0-preview27 208 10/26/2023
1.0.0-preview26 201 10/25/2023
1.0.0-preview25 212 10/23/2023
1.0.0-preview24 198 10/23/2023
1.0.0-preview23 199 10/23/2023
1.0.0-preview22 176 10/23/2023
1.0.0-preview21 211 10/23/2023
1.0.0-preview20 209 10/20/2023
1.0.0-preview19 181 10/19/2023
1.0.0-preview18 235 10/18/2023
1.0.0-preview16 254 10/11/2023
1.0.0-preview101 185 1/5/2024