09 ABP Framework 中的 MVC 和 Razor Pages

发布于:2025-08-14 ⋅ 阅读:(21) ⋅ 点赞:(0)

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.0
  • Nullable:enable
  • MvcRazorExcludeRefAssembliesFromPublish:false(用于正确的 Razor 编译)
  • PreserveCompilationReferences:true(用于运行时编译)

开发与生产环境

模板支持开发和生产环境的不同配置:

开发环境功能:

  • 运行时 Razor 编译
  • 嵌入式文件提供程序
  • 用户机密集成
  • 详细错误页面

生产环境功能:

  • 资源打包和压缩
  • 使用 Redis 的分布式缓存
  • 使用 Redis 的数据保护
  • 分布式锁定

网站公告

今日签到

点亮在社区的每一天
去签到