🚀 Quick Start
Prerequisites
- .NET 10 SDK
- MySQL (or other database supported by FreeSql)
- (Optional) Redis
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
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
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
builder.AddEasyAdminBlazor(new EasyAdminBlazorOptions
{
EnableLoginCaptcha = true,
EnableMessage =true,
ShowHelp =true,
AesKey= "XME2k7nA9vJy9osiU389469Y",
AdminRouteSecret= "i4ByMAX4",
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();
app.MapRazorComponents<App>()
.AddAdditionalAssemblies(typeof(EasyAdminBlazor._Imports).Assembly)
.AddInteractiveServerRenderMode();
// Use Session
app.UseSession();
app.UseChat();
app.UseEasyAdminBlazor();
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,
"MaxImageWidth": 800,
"WebpQuality": 80
},
"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"
}
}