ABP Framework 中的 MVC 和 Razor Pages
該頁面詳細介紹了 ABP Framework 與 ASP.NET Core MVC 和 Razor Pages 的集成,涵蓋框架組件、項目模板、主題系統和模塊集成模式等內容,提供了 ABP 應用程序中傳統的服務器端 Web UI 選項。
框架集成組件
ABP 提供了多個核心包用于 MVC 和 Razor Pages 集成,以擴展 ASP.NET Core 的功能,主要包括:
Multi-Tenancy Support
Theme System
Core MVC Framework
Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy Tenant UI Components
Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared Common Theme Infrastructure
Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite Default Theme
Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic Simple Theme
Volo.Abp.AspNetCore.Mvc Core MVC Integration
Volo.Abp.AspNetCore.Mvc.UI UI Extensions
Volo.Abp.AspNetCore.Mvc.UI.Bundling Asset Management
項目模板類型
ABP 提供了多種 MVC/Razor Pages 項目模板,適用于不同的架構模式和部署場景。
應用程序模板模板類型 項目名稱 目的 主要功能 Layered Web Application MyCompanyName.MyProjectName.Web
全功能 Web 應用程序 完整的業務層集成 Tiered Web Host MyCompanyName.MyProjectName.Web.Host
分布式架構的前端 HTTP 客戶端集成、Redis 緩存 Authentication Server MyCompanyName.MyProjectName.AuthServer
專用身份驗證服務 OpenIddict 集成、分布式鎖定 無分層 MVC MyCompanyName.MyProjectName.Mvc
簡化的單項目結構 一體化架構
Layered Architecture
Tiered Architecture
No-layers Architecture
MyCompanyName.MyProjectName.Web Full Web Application
Application Layer
Entity Framework Layer
HTTP API Layer
MyCompanyName.MyProjectName.Web.Host UI Frontend
Separate API Host
MyCompanyName.MyProjectName.AuthServer Authentication Server
MyCompanyName.MyProjectName.Mvc All-in-one Application
Integrated Modules
數據庫提供程序支持
模板通過不同的項目變體支持多種數據庫提供程序:
SQL Server :默認的 Entity Framework Core 集成MongoDB :帶有 MongoDB 提供程序的 NoSQL 替代方案Multiple Providers :通過單獨的包支持 Oracle、PostgreSQL、MySQL
主題系統集成
MVC 集成包含一個全面的主題系統,提供跨應用程序的一致 UI 組件和樣式。
Theme Architecture
Available Themes
Theme Features
ITheme Interface Theme Contract
Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared Common Components
Layout Templates
Navigation Components
CSS/JS Bundling
Multi-language Support
LeptonXLite Theme Modern Bootstrap Theme
Basic Theme Simple Bootstrap Theme
模塊集成模式
ABP MVC 應用程序通過一致的模式與業務模塊集成,同時提供后端服務和 UI 組件。
Identity Module
Tenant Management
Settings Management
Web Application
Volo.Abp.Identity.Web UI Components
Volo.Abp.Identity.Application Business Logic
Volo.Abp.Identity.EntityFrameworkCore Data Access
Volo.Abp.TenantManagement.Web UI Components
Volo.Abp.TenantManagement.Application Business Logic
Volo.Abp.TenantManagement.EntityFrameworkCore Data Access
Volo.Abp.SettingManagement.Web UI Components
Volo.Abp.SettingManagement.Application Business Logic
Volo.Abp.SettingManagement.EntityFrameworkCore Data Access
MVC Web Project
Razor Pages
MVC Controllers
資產管理與打包
MVC 應用程序使用 ABP 的打包系統進行高效的 CSS 和 JavaScript 管理。
打包配置
打包系統處理以下內容:
CSS/JS 壓縮和組合 特定主題的資源加載 開發與生產環境的優化 外部庫的 CDN 集成
文件組織模式:
Pages/
├── **/*.js # 頁面特定的 JavaScript
├── **/*.css # 頁面特定的 CSS
└── Shared/├── _Layout.cshtml└── Components/
身份驗證和授權集成
MVC 應用程序通過多個組件與 ABP 的身份驗證和授權系統集成。
Authorization
Security Infrastructure
Authentication Flow
Permission Management Role-based Access
Multi-tenancy Support Tenant Isolation
Feature Management Feature Flags
Redis Data Protection Distributed Sessions
Distributed Locking Concurrency Control
MVC Web Application
Volo.Abp.Account.Web.OpenIddict Account Management UI
OpenIddict Integration OAuth/OIDC Provider
ASPNET Core Identity User Management
配置和部署
項目配置
MVC 項目包括標準的 ABP 配置模式:
User Secrets :開發時配置存儲Embedded Resources :本地化文件和證書Runtime Compilation :開發中的 Razor 視圖編譯Logging :結構化日志的 Serilog 集成
常見項目屬性:
TargetFramework
:net9.0Nullable
:enableMvcRazorExcludeRefAssembliesFromPublish
:false(用于正確的 Razor 編譯)PreserveCompilationReferences
:true(用于運行時編譯)
開發與生產環境
模板支持開發和生產環境的不同配置:
開發環境功能:
運行時 Razor 編譯 嵌入式文件提供程序 用戶機密集成 詳細錯誤頁面
生產環境功能:
資源打包和壓縮 使用 Redis 的分布式緩存 使用 Redis 的數據保護 分布式鎖定