Indiko.Hosting.BlazorServer
2.2.2
See the version list below for details.
dotnet add package Indiko.Hosting.BlazorServer --version 2.2.2
NuGet\Install-Package Indiko.Hosting.BlazorServer -Version 2.2.2
<PackageReference Include="Indiko.Hosting.BlazorServer" Version="2.2.2" />
<PackageVersion Include="Indiko.Hosting.BlazorServer" Version="2.2.2" />
<PackageReference Include="Indiko.Hosting.BlazorServer" />
paket add Indiko.Hosting.BlazorServer --version 2.2.2
#r "nuget: Indiko.Hosting.BlazorServer, 2.2.2"
#:package Indiko.Hosting.BlazorServer@2.2.2
#addin nuget:?package=Indiko.Hosting.BlazorServer&version=2.2.2
#tool nuget:?package=Indiko.Hosting.BlazorServer&version=2.2.2
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();
Cookie Authentication
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.AbstractionsIndiko.Blocks.Common.AbstractionsIndiko.Blocks.Common.ManagementMicrosoft.AspNetCore.AppMicrosoft.AspNetCore.Authentication.OpenIdConnectNetEscapades.AspNetCore.SecurityHeaders
License
See LICENSE file in the repository root.
Related Packages
Indiko.Hosting.Abstractions- Core hosting abstractionsIndiko.Hosting.Web- Web API hostingIndiko.Hosting.Mvc- MVC hostingIndiko.Blocks.Security.Authentication.ASPNetCore- Additional authentication featuresIndiko.Blocks.Security.AuthenticationProvider.Blazor- Blazor authentication providers
| Product | Versions 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. |
-
net10.0
- Asp.Versioning.Mvc (>= 8.1.1)
- Asp.Versioning.Mvc.ApiExplorer (>= 8.1.1)
- Indiko.Hosting.Abstractions (>= 2.2.2)
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 10.0.3)
- Microsoft.AspNetCore.Razor.Language (>= 6.0.36)
- Microsoft.AspNetCore.WebUtilities (>= 10.0.3)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.3)
- Microsoft.Extensions.DependencyModel (>= 10.0.3)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.16.0)
- NetEscapades.AspNetCore.SecurityHeaders (>= 1.3.1)
- NetEscapades.AspNetCore.SecurityHeaders.TagHelpers (>= 1.3.1)
- System.IdentityModel.Tokens.Jwt (>= 8.16.0)
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.2.18 | 0 | 3/8/2026 |
| 2.2.17 | 0 | 3/8/2026 |
| 2.2.16 | 0 | 3/8/2026 |
| 2.2.15 | 29 | 3/7/2026 |
| 2.2.13 | 26 | 3/7/2026 |
| 2.2.12 | 29 | 3/7/2026 |
| 2.2.10 | 33 | 3/6/2026 |
| 2.2.9 | 32 | 3/6/2026 |
| 2.2.8 | 31 | 3/6/2026 |
| 2.2.7 | 34 | 3/6/2026 |
| 2.2.5 | 38 | 3/6/2026 |
| 2.2.3 | 32 | 3/6/2026 |
| 2.2.2 | 34 | 3/6/2026 |
| 2.2.1 | 32 | 3/6/2026 |
| 2.2.0 | 39 | 3/6/2026 |
| 2.1.4 | 84 | 3/2/2026 |
| 2.1.3 | 85 | 2/27/2026 |
| 2.1.2 | 305 | 12/18/2025 |
| 2.1.1 | 696 | 12/2/2025 |
| 2.1.0 | 683 | 12/2/2025 |