Deploy Blazor + Authentication + Postgres

Blazor Server with ASP.NET Identity auth and PostgreSQL - production ready

Deploy Blazor + Authentication + Postgres

Just deployed

/var/lib/postgresql/data

Deploy and Host Blazor + Authentication on Railway

A production-ready Blazor Server template with complete ASP.NET Identity authentication system and PostgreSQL database. Build secure web applications with user registration, login, password management, and role-based access control. Zero configuration required - deploy and immediately start building authenticated features.

About Hosting Blazor + Authentication

This template deploys a complete authentication-ready Blazor Server application with ASP.NET Identity and PostgreSQL. Railway handles the Docker build process that compiles your .NET 9 application, provisions a PostgreSQL database, and runs Entity Framework Core migrations automatically to create all necessary Identity tables (users, roles, claims, tokens). The authentication system includes secure password hashing with bcrypt, cookie-based session management, anti-forgery protection, and built-in account management pages. Health checks are pre-configured at /health for Railway monitoring. Public networking is enabled with automatic SSL certificates. After deployment, users can immediately register accounts, login, manage profiles, and access protected pages. The entire authentication stack deploys in under 3 minutes with zero manual configuration.

Common Use Cases

  • SaaS applications and web platforms - Multi-tenant systems with user accounts, subscriptions, and role-based feature access
  • Internal business applications - Employee dashboards, admin panels, CRM systems with department-based permissions
  • E-commerce and customer portals - User accounts, order history, wishlists, and personalized shopping experiences
  • Content management systems - Author/editor workflows with role-based publishing permissions and content approval
  • Educational platforms and LMS - Student/teacher accounts, course enrollment, progress tracking, and grade management
  • Social and community platforms - User profiles, authentication, followers, private messaging, and user-generated content
  • Project management tools - Team collaboration with user accounts, project permissions, and activity tracking

Dependencies for Blazor + Authentication Hosting

  • .NET 9 SDK - Provided via mcr.microsoft.com/dotnet/sdk:9.0 Docker image for compilation
  • ASP.NET Identity - Built-in authentication framework included with ASP.NET Core
  • PostgreSQL - Automatically provisioned by Railway with DATABASE_PUBLIC_URL environment variable
  • Entity Framework Core - ORM for database operations (Npgsql.EntityFrameworkCore.PostgreSQL)
  • Blazor Server - Interactive server-side rendering with SignalR real-time communication

Deployment Dependencies

Implementation Details

Complete Authentication System: ASP.NET Identity provides enterprise-grade user management out of the box:

// Identity automatically configured in Program.cs
builder.Services.AddIdentityCore(options => 
{
    options.SignIn.RequireConfirmedAccount = true;
    options.Password.RequireDigit = true;
    options.Password.RequiredLength = 6;
})
.AddEntityFrameworkStores()
.AddSignInManager()
.AddDefaultTokenProviders();

Built-In Account Pages:

  • /Account/Register - User registration with email and password
  • /Account/Login - Secure login with remember me option
  • /Account/Logout - Sign out endpoint
  • /Account/Manage - Profile management dashboard
  • /Account/Manage/Email - Change email address
  • /Account/Manage/Password - Change password
  • /Account/Manage/TwoFactorAuthentication - Enable 2FA

Protecting Pages with Authentication: Simple attribute-based authorization:

@page "/dashboard"
@attribute [Authorize]

Dashboard
<h1>Protected Dashboard</h1>


    
        <p>Welcome, @context.User.Identity?.Name!</p>
    
    
        <p>Please log in to access this page.</p>
    

Role-Based Authorization: Control access based on user roles:

@attribute [Authorize(Roles = "Admin")]

<h1>Admin-Only Page</h1>
<p>Only administrators can see this content.</p>

Database Schema Auto-Created: Identity migrations create complete user management tables:

  • AspNetUsers - User accounts with hashed passwords
  • AspNetRoles - Role definitions (Admin, User, etc.)
  • AspNetUserRoles - User-role assignments
  • AspNetUserClaims - Custom user claims
  • AspNetUserLogins - External authentication providers
  • AspNetUserTokens - Authentication and reset tokens
  • AspNetRoleClaims - Role-based permissions

Automatic Database Migration: Migrations run on every deployment automatically:

// Auto-migrate database on startup
using (var scope = app.Services.CreateScope())
{
    var db = scope.ServiceProvider.GetRequiredService();
    db.Database.Migrate();
}

Secure Password Storage: Passwords are hashed using ASP.NET Identity's secure hashing algorithm (PBKDF2-based with random salt). Passwords are never stored in plain text.

Railway Environment Detection: Automatically uses Railway's PostgreSQL connection:

var databaseUrl = Environment.GetEnvironmentVariable("DATABASE_PUBLIC_URL") 
                  ?? Environment.GetEnvironmentVariable("DATABASE_URL");

if (!string.IsNullOrEmpty(databaseUrl))
{
    connectionString = ConvertToEFConnectionString(databaseUrl);
}

Security Features Included:

  • HTTPS enforcement in production
  • Anti-CSRF tokens on all forms
  • XSS protection via Blazor's automatic HTML escaping
  • SQL injection protection with EF Core parameterized queries
  • Secure cookie configuration (HttpOnly, Secure, SameSite)
  • Password strength requirements (configurable)

Adding Custom User Properties: Extend the user model easily:

public class ApplicationUser : IdentityUser
{
    public string? FirstName { get; set; }
    public string? LastName { get; set; }
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}

Then create a migration and deploy - Railway handles the rest.

Customizable Password Requirements: Configure password rules to meet your needs:

options.Password.RequireDigit = true;
options.Password.RequiredLength = 8;
options.Password.RequireNonAlphanumeric = true;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = true;

External Authentication Ready: Add Google, Microsoft, Facebook, or other providers:

builder.Services.AddAuthentication()
    .AddGoogle(options =&gt;
    {
        options.ClientId = configuration["Google:ClientId"];
        options.ClientSecret = configuration["Google:ClientSecret"];
    });

Performance Characteristics:

  • User registration: < 100ms
  • Login verification: < 50ms
  • Password hashing: Secure (intentionally slower for security)
  • Database queries: Optimized with EF Core
  • Session management: Cookie-based, no database lookups

Why Deploy Blazor + Authentication on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Blazor + Authentication on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Additional Benefits:

  • Zero Configuration - Database, migrations, and auth work immediately after deployment
  • Production Security - HTTPS, secure cookies, password hashing all configured automatically
  • Instant Deployment - From git push to authenticated app in under 3 minutes
  • Auto-Scaling - Handle growing user bases with Railway's infrastructure
  • Built-in Monitoring - Health checks and deployment logs for auth services
  • Database Management - PostgreSQL provisioned, backed up, and managed by Railway
  • Cost-Effective - Only pay for actual usage as your user base grows

Template Content

More templates in this category

View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

View Template
Mellow Vue
A full-stack Vue app with The Boring JavaScript Stack.

View Template
NextJS 15.5 (Server Actions) with Shadcn
Better-Auth Ready with Auth flows and Server actions (Prod ready)