Quick Start
Prerequisites
- .NET 10 SDK
- Database: a new project from the template ships with SQLite by default. For production, switch to MySQL, SQL Server, PostgreSQL, or any database supported by FreeSql.
- (Optional) Redis (required by extensions such as chat and distributed cache)
New Project
# Install the template package
dotnet new install EasyAdminBlazor.Templates
# Create a project using the template
dotnet new easyadmin -n MyProjectName
# Navigate to the project and run
cd MyProjectName
dotnet run
Open the admin login page at http://localhost:port/admin/{secret}. The secret is an 8-character code generated randomly on first startup; it is printed in the console log (and kept in .aspnet/admin-route-secret.txt, so it survives restarts). The port is shown in the console startup log as well. Default account: admin, password: 123yyq.
Existing Project
Step 1: Install NuGet Packages
# Core package (required)
dotnet add package EasyAdminBlazor
# Database provider (choose based on your database)
dotnet add package FreeSql.Provider.MySqlConnector # MySQL
dotnet add package FreeSql.Provider.SqlServer # SQL Server
dotnet add package FreeSql.Provider.Sqlite # SQLite
dotnet add package FreeSql.Provider.PostgreSQL # PostgreSQL
Step 2: Configure Program.cs
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
builder.AddEasyAdminBlazor(new EasyAdminBlazorOptions
{
EnableLoginCaptcha = true,
EnableMessage =true,
ShowHelp =true,
AesKey= "XME2k7nA9vJy9osiU389469Y",
// Server-side login ticket lifetime (also used for the "remember me" cookie)
TicketLifetime = TimeSpan.FromDays(7),
// Admin entry secret: leave it empty and the admin route has no protection; "REPLACE8" is only a placeholder -- replace it with your own random 8-character value
AdminRouteSecret= "REPLACE8",
Assemblies = [typeof(Program).Assembly],
FreeSqlBuilder = a => a
.UseConnectionString(DataType.MySql, configuration["ConnectionStrings:default"])
.UseMonitorCommand(cmd => System.Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] {cmd.CommandText}\r\n"))
.UseAutoSyncStructure(true)
})
.AddEasyAdminBlazorMail()
.AddEasyAdminBlazorTinyMCEEditor()
.AddEasyAdminBlazorRedis(configuration["Redis:ConnectionString"]!)
.AddEasyAdminBlazorChat()
.AddEasyAdminBlazorWeChat()
.AddEasyAdminBlazorScheduler()
.AddEasyAdminBlazorFusionCache()
.AddEasyAdminBlazorMultiTenant()
.AddEasyAdminBlazorCaptcha(options =>
{
options.Chars = "0123456789";
});
// Add services to the container.
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// Register Session services
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddBootstrapBlazorTableExportService();
builder.Services.Configure<HubOptions>(option => {
option.MaximumReceiveMessageSize = null;
});
var app = builder.Build();
// If EnableLocalization=true, uncomment the following:
//var option = app.Services.GetService<IOptions<RequestLocalizationOptions>>();
//if (option != null)
//{
// app.UseRequestLocalization(option.Value);
//}
app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All });
app.UseStaticFiles();
app.UseAntiforgery();
// Use Session
app.UseSession();
app.UseChat();
// Pass the host's App component (Components/App.razor); framework and extension assemblies are mapped automatically
app.UseEasyAdminBlazor<App>();
app.Run();
Step 3: Complete appsettings.json Configuration Example
{
"ConnectionStrings": {
"Default": "Data Source=127.0.0.1;Port=3306;User ID=root;Password=123456; Initial Catalog=freesql_simple;Charset=utf8mb4; SslMode=none;Min pool size=1"
},
"Redis": {
"ConnectionString": "127.0.0.1:6379,poolsize=10"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"FileSettings": {
"DirectoryName": "uploads",
"IncludeExtension": [".jpg", ".jpeg", ".png", ".gif", ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".txt", ".webp"],
"ExcludeExtension": [".exe", ".dll", ".jar", ".php", ".aspx", ".bat", ".cmd", ".vbs", ".js", ".html", ".htm"],
"DateTimeDirectory": "yyyy/MM/dd",
"KeepOriginalFile": false, //true: keep non-WebP originals (no conversion/resizing); oversized WebP originals are still resized; false: compress and convert to WebP
"MaxImageWidth": 800,
"WebpQuality": 80,
"MaxImagePixels": 40000000
},
"SmtpSettings": {
"Server": "smtp.example.com",
"Port": 587,
"Username": "your_email@example.com",
"Password": "your_email_password",
"FromEmail": "your_email@example.com",
"EnableSsl": true
},
"Wechat": {
"App": {
"AppKey": "your_app_key",
"AppSecret": "your_app_secret"
},
"PayV3": {
"AppId": "",
"MchId": "",
"ApiV3Key": "",
"CertificatePath": "certs/apiclient_cert.pem",
"KeyPath": "certs/apiclient_key.pem",
"PubPath": "certs/pub_key.pem",
"NotifyUrl": "",
"BaseUrl": "https://api.mch.weixin.qq.com"
}
},
"TinyMCE": {
"ScriptSrc": "https://cdn.wang-zhan.cn/tinymce_8.3.2/tinymce.min.js"
},
"BootstrapBlazorOptions": {
"ToastDelay": 4000,
"MessageDelay": 4000,
"SwalDelay": 4000,
"EnableErrorLogger": true,
"FallbackCulture": "en",
"SupportedCultures": ["zh-CN", "en-US"],
"TableSettings": {
"CheckboxColumnWidth": 36
},
"WebClientOptions": {
"EnableIpLocator": true
},
"IgnoreLocalizerMissing": true,
"StepSettings": {
"Short": "1",
"Int": "1",
"Long": "1",
"Float": "0.1",
"Double": "0.01",
"Decimal": "0.01"
},
"DefaultCultureInfo": "zh-CN"
}
}
Step 4: Add the App.razor Page Under the Project's Components Folder
<!DOCTYPE html>
<html lang="en" data-bs-theme='light'>
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="keywords" content="admin template,bootstrap,blazor,wasm,webassembly,UI,netcore,web,assembly">
<meta name="description" content="Admin dashboard built on Bootstrap and FreeSql for enterprise back-office products.">
<meta name="author" content="gudufy (84383822@qq.com) www.wang-zhan.com.cn">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon" href="favicon.png">
<base href="/" />
<link rel="stylesheet" href="@Assets["_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css"]" />
<link rel="stylesheet" href="@Assets["_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css"]" />
<link rel="stylesheet" href="@Assets["_content/EasyAdminBlazor/ant.css"]">
<link rel="stylesheet" href="@Assets["_content/EasyAdminBlazor/adminblazor.css"]" />
<link rel="stylesheet" href="@Assets["EasyAdminBlazor.styles.css"]" />
<!-- The following file is "your project name.styles.css"; replace MyProjectName with your project name -->
<link rel="stylesheet" href="@Assets["MyProjectName.styles.css"]" />
<title>Admin Dashboard - EasyAdminBlazor</title>
<ImportMap></ImportMap>
<HeadOutlet @rendermode="new InteractiveServerRenderMode(false)" />
</head>
<body>
<Routes @rendermode="new InteractiveServerRenderMode(false)" />
<ReconnectorOutlet ReconnectInterval="5000" @rendermode="new InteractiveServerRenderMode(false)" />
@* Chinese/English templates for the connection-lost notice (built into the framework, follows the current culture) *@
<EasyAdminReconnector @rendermode="new InteractiveServerRenderMode(false)" />
<script Src="_content/BootstrapBlazor/js/bootstrap.blazor.bundle.min.js"></script>
<script src="_framework/blazor.web.js"></script>
<script src="@Assets["_content/EasyAdminBlazor/adminblazor.js"]"></script>
<script Src="@Assets["_content/EasyAdminBlazor.HtmlEditor/TinyMCEEditor.razor.js"]"></script>
</body>
</html>
ReconnectorOutletshows the notice when the connection drops and reloads the page once the server is back;EasyAdminReconnectorsupplies the notice text (from the framework's built-in language packs, so it switches between Chinese and English automatically). Both must use the same render mode and live on the same page, otherwise the templates are not applied (the UI falls back to BootstrapBlazor's default English text).
Step 5: Add the Routes.razor Page Under the Project's Components Folder
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(MainLayout).Assembly }">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
</Router>
Step 6: Run the Project
dotnet run
Admin login URL: http://localhost:PORT/admin/{secret} ({secret} is the AdminRouteSecret configured in the previous step; the port comes from the startup log). Default administrator: admin / 123yyq. The default tenant password is generated from the tenant code (e.g. vip123).
Next Steps
- Documentation Index: all documents and the reading order
- Starting a New Module: add your first business module
- Code Generation: generate CRUD pages with the code generator