XFrameBack.Web
1.0.8
dotnet add package XFrameBack.Web --version 1.0.8
NuGet\Install-Package XFrameBack.Web -Version 1.0.8
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XFrameBack.Web" Version="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XFrameBack.Web" Version="1.0.8" />
<PackageReference Include="XFrameBack.Web" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add XFrameBack.Web --version 1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: XFrameBack.Web, 1.0.8"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package XFrameBack.Web@1.0.8
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=XFrameBack.Web&version=1.0.8
#tool nuget:?package=XFrameBack.Web&version=1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
XFrameBack.Web
用于积累 .NET 6、.NET 8、.NET 10 Web 中间件等成果的类库。
支持框架
- .NET 6.0
- .NET 8.0
- .NET 10.0
功能特性
1. Hprose RPC 服务
Hprose 是一个高性能的 RPC 框架,本项目提供了完整的 ASP.NET Core 集成。
// 注入 Hprose 服务
services.AddHproseServices(assembly, "Services");
// 或通过类型列表注入
services.AddHproseServicesByTypes(serviceTypesList);
相关文件:
Extensions/HproseServiceExtension.cs- Hprose 服务注册扩展Middlewares/Hprose/HproseMiddleware.cs- Hprose 中间件GCBridge/Hprose/- Hprose 属性和元数据定义
2. SqlSugar ORM 集成
支持单数据库和多租户模式。
// 注册 SqlSugar 客户端
services.AddSqlSugarClient("SqlSugarOptions");
配置示例 (appsettings.json):
{
"SqlSugarOptions": {
"SingleDB": {
"DbType": 1,
"ConnectionString": "Server=localhost;Database=Test;Uid=root;Pwd=123456;"
}
}
}
相关文件:
Extensions/SqlsugarClientExtension.cs- SqlSugar 客户端注册Models/SqlSugarOptions.cs- SqlSugar 配置模型
3. Token 验证中间件
用户身份验证和 Token 刷新机制。
// 添加 Token 验证服务
services.AddValidationToken("http://localhost:5000/api", 30);
// 使用 Token 验证中间件
app.UseValidationToken();
功能:
- 支持从 Header 或 QueryString 获取 Token
- 支持 AccessToken 和 RefreshToken 双重 Token
- 分布式缓存存储用户状态
- 自动刷新过期 Token
相关文件:
Middlewares/ValidationTokenMiddleware.cs- Token 验证中间件Models/IUserState.cs- 用户状态模型
4. IP 限流
基于 AspNetCoreRateLimit 实现的 IP 级别请求限流。
// 添加 IP 限流
services.AddIPRateLimit();
// 使用限流中间件
app.UseIpRateLimiting();
配置示例 (appsettings.json):
{
"IpRateLimiting": {
"EnableEndpointRateLimiting": true,
"StackCidrEntries": 10,
"GeneralRules": [
{
"Endpoint": "*",
"Period": "1s",
"Limit": 4
}
]
}
}
相关文件:
Extensions/IPRateLimitExtension.cs- IP 限流扩展
5. CORS 跨域中间件
支持配置化跨域请求。
// 添加全局 CORS
services.AddGlobalCors();
// 使用 CORS 中间件
app.UseGlobalCors();
配置示例 (appsettings.json):
{
"CORS": {
"AllCrossDomain": false,
"Origins": ["http://localhost:3000", "http://localhost:8080"]
}
}
相关文件:
Middlewares/Http/AllCORSMiddleware.cs- CORS 中间件Extensions/GlobalCorsExtension.cs- CORS 扩展Models/Cors.cs- CORS 配置模型
6. 全局配置与 IOC
统一的配置管理和依赖注入容器。
// 绑定配置
var app = builder.Build();
app.BindConfiguration(builder.Configuration);
// 绑定服务
app.Services.BindServices();
// 获取配置值
var value = Global.GetValue<string>("Key");
var options = Global.GetValue<SqlSugarOptions>();
// 获取注册服务
var service = Global.GetSerivce<IMyService>();
相关文件:
Core/Global.cs- 全局静态类
7. 分页模型
通用的分页列表模型,支持同步/异步、JSON/对象模式。
// 从 ISugarQueryable 创建分页
var pagedList = await PagedList<T>.CreateAsyncJson(query, pageIndex, pageSize);
// 从 IList 创建分页
var pagedList = await PagedList<T>.CreateAsync(list, pageIndex, pageSize);
相关文件:
Models/PagedList.cs- 分页列表模型
8. 工具类
HashUtil - 哈希工具
// SHA256 加密
var hash = HashUtil.HashData256("input");
var hexString = HashUtil.HashToHexString256("input");
// SHA512 加密
var hash = HashUtil.HashData512("input");
var hexString = HashUtil.HashToHexString512("input");
DataTableUtil - DataTable 工具
AssemblyHelper - 程序集辅助类
相关文件:
Utils/HashUtil.csUtils/DataTableUtil.csUtils/AssemblyHelper.cs
项目结构
XFrameBack.Web/
├── Core/ # 核心功能
│ └── Global.cs # 全局静态类
├── Extensions/ # 扩展方法
│ ├── ConfigureExtension.cs
│ ├── ControllerWithJson.cs
│ ├── GlobalCorsExtension.cs
│ ├── HproseServiceExtension.cs
│ ├── HproseContextExtension.cs
│ ├── IPRateLimitExtension.cs
│ ├── ModelsIOCExtension.cs
│ ├── IHttpSessionExtension.cs
│ └── SqlsugarClientExtension.cs
├── GCBridge/ # Hprose 网关桥接
│ └── Hprose/
├── Middlewares/ # 中间件
│ ├── Http/
│ │ ├── AllCORSMiddleware.cs
│ │ ├── CORSOptions.cs
│ │ └── ZHttpContext.cs
│ ├── Hprose/
│ │ ├── HproseMiddleware.cs
│ │ └── HproseOptions.cs
│ └── ValidationTokenMiddleware.cs
├── Models/ # 数据模型
│ ├── Cors.cs
│ ├── IUserState.cs
│ ├── PagedList.cs
│ └── SqlSugarOptions.cs
└── Utils/ # 工具类
├── AssemblyHelper.cs
├── DataTableUtil.cs
└── HashUtil.cs
依赖包
| 包名 | 版本 | 说明 |
|---|---|---|
| AspNetCoreRateLimit | 5.0.0 | IP 限流 |
| Hprose.RPC.AspNetCore | 3.0.22 | RPC 框架 |
| Microsoft.IdentityModel.JsonWebTokens | 8.18.0 | JWT 支持 |
| RestSharp | 114.0.0 | HTTP 客户端 |
| SqlSugar.IOC | 2.0.1 | ORM IOC |
| SqlSugarCore | 5.1.4.214 | ORM 核心 |
使用示例
完整配置示例
var builder = WebApplication.CreateBuilder(args);
// 1. 绑定配置
builder.Configuration.BindConfiguration();
// 2. 绑定服务容器
builder.Services.BindServices();
// 3. 添加 CORS
builder.Services.AddGlobalCors();
// 4. 添加 SqlSugar
builder.Services.AddSqlSugarClient();
// 5. 添加 IP 限流
builder.Services.AddIPRateLimit();
// 6. 添加 Token 验证
builder.Services.AddValidationToken("http://localhost:5000/api", 30);
var app = builder.Build();
// 7. 使用中间件
app.UseGlobalCors();
app.UseIpRateLimiting();
app.UseValidationToken();
app.Run();
appsettings.json 配置示例
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"SqlSugarOptions": {
"SingleDB": {
"DbType": 1,
"ConnectionString": "Server=localhost;Database=Test;Uid=root;Pwd=123456;"
}
},
"CORS": {
"AllCrossDomain": false,
"Origins": ["http://localhost:3000"]
},
"IpRateLimiting": {
"EnableEndpointRateLimiting": true,
"StackCidrEntries": 10,
"GeneralRules": [
{
"Endpoint": "*",
"Period": "1s",
"Limit": 10
}
]
}
}
版本历史
- v1.0.8 - 最新版本
- v1.0.7 - 更新内容
- v1.0.6 - 更新内容
- ...
许可证
内部积累,公开使用
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- AspNetCoreRateLimit (>= 5.0.0)
- Hprose.RPC.AspNetCore (>= 3.0.22)
- Microsoft.AspNetCore (>= 2.3.10)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.18.0)
- RestSharp (>= 114.0.0)
- SqlSugar.IOC (>= 2.0.1)
- SqlSugarCore (>= 5.1.4.214)
-
net6.0
- AspNetCoreRateLimit (>= 5.0.0)
- Hprose.RPC.AspNetCore (>= 3.0.22)
- Microsoft.AspNetCore (>= 2.3.10)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.18.0)
- RestSharp (>= 114.0.0)
- SqlSugar.IOC (>= 2.0.1)
- SqlSugarCore (>= 5.1.4.214)
-
net8.0
- AspNetCoreRateLimit (>= 5.0.0)
- Hprose.RPC.AspNetCore (>= 3.0.22)
- Microsoft.AspNetCore (>= 2.3.10)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.18.0)
- RestSharp (>= 114.0.0)
- SqlSugar.IOC (>= 2.0.1)
- SqlSugarCore (>= 5.1.4.214)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
根据新web模板修改,增加Extensions