😎1、优化响应安全头 2、增加枚举验证特性
This commit is contained in:
parent
b04f354f96
commit
5f4f3d2ee7
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
"AppSettings": {
|
"AppSettings": {
|
||||||
"InjectSpecificationDocument": true, // 生产环境是否开启Swagger
|
"InjectSpecificationDocument": true, // 生产环境是否开启Swagger
|
||||||
"ExternalAssemblies": [ "plugins" ] // 插件目录
|
"ExternalAssemblies": [ "plugins" ], // 插件目录
|
||||||
|
"VirtualPath": "" // 二级虚拟目录
|
||||||
},
|
},
|
||||||
"DynamicApiControllerSettings": {
|
"DynamicApiControllerSettings": {
|
||||||
//"DefaultRoutePrefix": "api", // 默认路由前缀
|
//"DefaultRoutePrefix": "api", // 默认路由前缀
|
||||||
|
|||||||
@ -22,12 +22,12 @@
|
|||||||
"DefaultGroupName": "Default", // 默认分组名
|
"DefaultGroupName": "Default", // 默认分组名
|
||||||
"DocExpansionState": "List", // List、Full、None
|
"DocExpansionState": "List", // List、Full、None
|
||||||
"EnableAllGroups": true,
|
"EnableAllGroups": true,
|
||||||
//"ServerDir": "t490", // Nginx 有二级目录的,把二级目录设置在这里,并且开启 Servers 的选择列表
|
//"ServerDir": "xxx", // 二级虚拟目录并且开启 Servers 选择列表
|
||||||
"HideServers": true,
|
"HideServers": true,
|
||||||
"Servers": [
|
"Servers": [
|
||||||
{
|
{
|
||||||
"Url": "https://ip/二级",
|
"Url": "http://ip/xxx",
|
||||||
"Description": "发布地址名称"
|
"Description": "应用程序名"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"LoginInfo": {
|
"LoginInfo": {
|
||||||
|
|||||||
50
Admin.NET/Admin.NET.Core/Attribute/EnumAttribute.cs
Normal file
50
Admin.NET/Admin.NET.Core/Attribute/EnumAttribute.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||||
|
//
|
||||||
|
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||||
|
//
|
||||||
|
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||||
|
|
||||||
|
namespace Admin.NET.Core;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 枚举值合规性校验特性
|
||||||
|
/// </summary>
|
||||||
|
[SuppressSniffer]
|
||||||
|
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Enum | AttributeTargets.Field, AllowMultiple = true)]
|
||||||
|
public class EnumAttribute : ValidationAttribute, ITransient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 枚举值合规性校验特性
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="errorMessage"></param>
|
||||||
|
public EnumAttribute(string errorMessage = "枚举值不合法!")
|
||||||
|
{
|
||||||
|
ErrorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 枚举值合规性校验
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
// 获取属性的类型
|
||||||
|
var property = validationContext.ObjectType.GetProperty(validationContext.MemberName);
|
||||||
|
if (property == null)
|
||||||
|
return new ValidationResult($"未知属性: {validationContext.MemberName}");
|
||||||
|
|
||||||
|
var propertyType = property.PropertyType;
|
||||||
|
|
||||||
|
// 检查属性类型是否为枚举
|
||||||
|
if (!propertyType.IsEnum)
|
||||||
|
return new ValidationResult($"属性类型'{validationContext.MemberName}'不是有效的枚举类型!");
|
||||||
|
|
||||||
|
// 检查枚举值是否有效
|
||||||
|
if (!Enum.IsDefined(propertyType, value))
|
||||||
|
return new ValidationResult($"提示:{ErrorMessage}|枚举值【{value}】不是有效的【{propertyType.Name}】枚举类型值!");
|
||||||
|
|
||||||
|
return ValidationResult.Success;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -14,6 +14,6 @@ public class BaseStatusInput : BaseIdInput
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 状态
|
/// 状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Dict(nameof(StatusEnum))]
|
[Enum]
|
||||||
public StatusEnum Status { get; set; }
|
public StatusEnum Status { get; set; }
|
||||||
}
|
}
|
||||||
@ -289,7 +289,7 @@ public class Startup : AppStartup
|
|||||||
// 强制使用 HTTPS,防止中间人攻击
|
// 强制使用 HTTPS,防止中间人攻击
|
||||||
context.Response.Headers.Append("Strict-Transport-Security", "max-age=63072000; includeSubDomains; preload");
|
context.Response.Headers.Append("Strict-Transport-Security", "max-age=63072000; includeSubDomains; preload");
|
||||||
// 隐藏服务器端技术栈
|
// 隐藏服务器端技术栈
|
||||||
context.Response.Headers.Append("X-Powered-By", "Admin.NET v2.0.0");
|
context.Response.Headers.Append("X-Powered-By", "Admin.NET");
|
||||||
// 移除特性响应头
|
// 移除特性响应头
|
||||||
context.Response.Headers.Remove("Furion");
|
context.Response.Headers.Remove("Furion");
|
||||||
// 添加自定义响应头
|
// 添加自定义响应头
|
||||||
@ -335,6 +335,16 @@ public class Startup : AppStartup
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// 二级目录文件路径解析
|
||||||
|
//if (!string.IsNullOrEmpty(App.Settings.VirtualPath))
|
||||||
|
//{
|
||||||
|
// app.UseStaticFiles(new StaticFileOptions
|
||||||
|
// {
|
||||||
|
// RequestPath = App.Settings.VirtualPath,
|
||||||
|
// FileProvider = App.WebHostEnvironment.WebRootFileProvider
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
//// 启用HTTPS
|
//// 启用HTTPS
|
||||||
//app.UseHttpsRedirection();
|
//app.UseHttpsRedirection();
|
||||||
|
|
||||||
@ -380,7 +390,7 @@ public class Startup : AppStartup
|
|||||||
options.ConfigObject.DisplayRequestDuration = true;
|
options.ConfigObject.DisplayRequestDuration = true;
|
||||||
foreach (var groupInfo in SpecificationDocumentBuilder.GetOpenApiGroups())
|
foreach (var groupInfo in SpecificationDocumentBuilder.GetOpenApiGroups())
|
||||||
{
|
{
|
||||||
// 兼容 Nginx 二级目录转发的情况(配置二级域名转发,还要使用 Swagger.json 的 ServerDir 配置项)
|
// 兼容二级虚拟目录转发(配置二级域名转发,需要 Swagger.json 的 ServerDir 配置项)
|
||||||
options.SwaggerEndpoint(string.Concat("..", groupInfo.RouteTemplate.AsSpan(groupInfo.RouteTemplate.IndexOf("/swagger/"))), groupInfo.Title);
|
options.SwaggerEndpoint(string.Concat("..", groupInfo.RouteTemplate.AsSpan(groupInfo.RouteTemplate.IndexOf("/swagger/"))), groupInfo.Title);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "admin.net.pro",
|
"name": "admin.net.pro",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.4.33",
|
"version": "2.4.33",
|
||||||
"lastBuildTime": "2025.01.11",
|
"lastBuildTime": "2025.01.12",
|
||||||
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
||||||
"author": "zuohuaijun",
|
"author": "zuohuaijun",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -60,7 +60,7 @@
|
|||||||
"screenfull": "^6.0.2",
|
"screenfull": "^6.0.2",
|
||||||
"sm-crypto-v2": "^1.9.3",
|
"sm-crypto-v2": "^1.9.3",
|
||||||
"sortablejs": "^1.15.6",
|
"sortablejs": "^1.15.6",
|
||||||
"splitpanes": "^3.1.5",
|
"splitpanes": "^3.1.6",
|
||||||
"vcrontab-3": "^3.3.22",
|
"vcrontab-3": "^3.3.22",
|
||||||
"vform3-builds": "^3.0.10",
|
"vform3-builds": "^3.0.10",
|
||||||
"vue": "^3.5.13",
|
"vue": "^3.5.13",
|
||||||
@ -70,7 +70,7 @@
|
|||||||
"vue-grid-layout": "3.0.0-beta1",
|
"vue-grid-layout": "3.0.0-beta1",
|
||||||
"vue-i18n": "^11.0.1",
|
"vue-i18n": "^11.0.1",
|
||||||
"vue-json-pretty": "^2.4.0",
|
"vue-json-pretty": "^2.4.0",
|
||||||
"vue-plugin-hiprint": "^0.0.59-beta1",
|
"vue-plugin-hiprint": "^0.0.59-beta2",
|
||||||
"vue-router": "^4.5.0",
|
"vue-router": "^4.5.0",
|
||||||
"vue-signature-pad": "^3.0.2",
|
"vue-signature-pad": "^3.0.2",
|
||||||
"vue3-tree-org": "^4.2.2",
|
"vue3-tree-org": "^4.2.2",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user