😎1、代码优化 2、升级依赖及升级.NET9.0
This commit is contained in:
parent
0ea36ba9cb
commit
e75edd5536
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591;8632</NoWarn>
|
<NoWarn>1701;1702;1591;8632</NoWarn>
|
||||||
<DocumentationFile></DocumentationFile>
|
<DocumentationFile></DocumentationFile>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
|||||||
@ -22,8 +22,7 @@
|
|||||||
"ThrowBah": true, // 是否将 Oops.Oh 默认抛出为业务异常
|
"ThrowBah": true, // 是否将 Oops.Oh 默认抛出为业务异常
|
||||||
"LogError": false // 是否输出异常日志
|
"LogError": false // 是否输出异常日志
|
||||||
},
|
},
|
||||||
// 静态资源处理方式(允许这些文件被访问)
|
// 静态资源处理方式(允许这些文件被访问),包含".*": "application/octet-stream"允许访问所有静态资源
|
||||||
// 包含".*": "application/octet-stream"允许访问所有静态资源
|
|
||||||
"StaticContentTypeMappings": {
|
"StaticContentTypeMappings": {
|
||||||
".dll": "application/octet-stream",
|
".dll": "application/octet-stream",
|
||||||
".exe": "application/octet-stream",
|
".exe": "application/octet-stream",
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591;8632</NoWarn>
|
<NoWarn>1701;1702;1591;8632</NoWarn>
|
||||||
<DocumentationFile></DocumentationFile>
|
<DocumentationFile></DocumentationFile>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
@ -18,9 +18,9 @@
|
|||||||
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" />
|
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" />
|
||||||
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
|
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
|
||||||
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.10" />
|
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.10" />
|
||||||
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.18" />
|
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.21" />
|
||||||
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.18" />
|
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.21" />
|
||||||
<PackageReference Include="Furion.Pure" Version="4.9.5.18" />
|
<PackageReference Include="Furion.Pure" Version="4.9.5.21" />
|
||||||
<PackageReference Include="Hardware.Info" Version="101.0.0" />
|
<PackageReference Include="Hardware.Info" Version="101.0.0" />
|
||||||
<PackageReference Include="Hashids.net" Version="1.7.0" />
|
<PackageReference Include="Hashids.net" Version="1.7.0" />
|
||||||
<PackageReference Include="IPTools.China" Version="1.6.0" />
|
<PackageReference Include="IPTools.China" Version="1.6.0" />
|
||||||
@ -43,9 +43,9 @@
|
|||||||
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="3.6.0" />
|
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="3.6.0" />
|
||||||
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="3.9.0" />
|
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="3.9.0" />
|
||||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
|
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
|
||||||
<PackageReference Include="SSH.NET" Version="2024.1.0" />
|
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
||||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.8" />
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.8" />
|
||||||
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1120" />
|
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1123" />
|
||||||
<PackageReference Include="UAParser" Version="3.1.47" />
|
<PackageReference Include="UAParser" Version="3.1.47" />
|
||||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -54,9 +54,9 @@
|
|||||||
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="6.0.15" />
|
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="6.0.15" />
|
||||||
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="6.0.15" />
|
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="6.0.15" />
|
||||||
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.6" />
|
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.6" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.33" />
|
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.36" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="6.0.33" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="6.0.36" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="6.0.33" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="6.0.36" />
|
||||||
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" />
|
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@ -64,9 +64,19 @@
|
|||||||
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="8.3.0" />
|
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="8.3.0" />
|
||||||
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="8.3.0" />
|
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="8.3.0" />
|
||||||
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.9" />
|
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.9" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.11" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="8.0.11" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.11" />
|
||||||
|
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.2.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
|
||||||
|
<PackageReference Include="AspNet.Security.OAuth.Gitee" Version="9.0.0" />
|
||||||
|
<PackageReference Include="AspNet.Security.OAuth.Weixin" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="9.0.0" />
|
||||||
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.2.0" />
|
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -11,25 +11,21 @@ public class CreateEntityInput
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 表名
|
/// 表名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <example>student</example>
|
|
||||||
public string TableName { get; set; }
|
public string TableName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实体名
|
/// 实体名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <example>Student</example>
|
|
||||||
public string EntityName { get; set; }
|
public string EntityName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 基类名
|
/// 基类名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <example>AutoIncrementEntity</example>
|
|
||||||
public string BaseClassName { get; set; }
|
public string BaseClassName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 导出位置
|
/// 导出位置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <example>Web.Application</example>
|
|
||||||
public string Position { get; set; }
|
public string Position { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,54 +1,49 @@
|
|||||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||||
//
|
//
|
||||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||||
//
|
//
|
||||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||||
|
|
||||||
namespace Admin.NET.Core.Service;
|
namespace Admin.NET.Core.Service;
|
||||||
|
|
||||||
public class CreateSeedDataInput
|
public class CreateSeedDataInput
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 库标识
|
/// 库标识
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ConfigId { get; set; }
|
public string ConfigId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 表名
|
/// 表名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <example>student</example>
|
public string TableName { get; set; }
|
||||||
public string TableName { get; set; }
|
|
||||||
|
/// <summary>
|
||||||
/// <summary>
|
/// 实体名称
|
||||||
/// 实体名称
|
/// </summary>
|
||||||
/// </summary>
|
public string EntityName { get; set; }
|
||||||
/// <example>Student</example>
|
|
||||||
public string EntityName { get; set; }
|
/// <summary>
|
||||||
|
/// 种子名称
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// 种子名称
|
public string SeedDataName { get; set; }
|
||||||
/// </summary>
|
|
||||||
/// <example>Student</example>
|
/// <summary>
|
||||||
public string SeedDataName { get; set; }
|
/// 导出位置
|
||||||
|
/// </summary>
|
||||||
/// <summary>
|
public string Position { get; set; }
|
||||||
/// 导出位置
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <example>Web.Application</example>
|
/// 后缀
|
||||||
public string Position { get; set; }
|
/// </summary>
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 后缀
|
|
||||||
/// </summary>
|
|
||||||
/// <example>Web.Application</example>
|
|
||||||
public string Suffix { get; set; }
|
public string Suffix { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 过滤已有数据
|
/// 过滤已有数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// 如果数据在其它不同名的已有的种子类型的数据中出现过,就不生成这个数据
|
/// 如果数据在其它不同名的已有的种子类型的数据中出现过,就不生成这个数据。
|
||||||
/// 主要用于生成菜单功能,菜单功能往往与子项目绑定,如果生成完整数据就会导致菜单项多处理重复。
|
/// 主要用于生成菜单功能,菜单功能往往与子项目绑定,如果生成完整数据就会导致菜单项多处理重复。
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public bool FilterExistingData { get; set; }
|
public bool FilterExistingData { get; set; }
|
||||||
}
|
}
|
||||||
@ -4,11 +4,9 @@
|
|||||||
//
|
//
|
||||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||||
|
|
||||||
using Mapster.Adapters;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Admin.NET.Core.Service;
|
namespace Admin.NET.Core.Service;
|
||||||
|
|
||||||
@ -358,29 +356,24 @@ public class SysDatabaseService : IDynamicApiController, ITransient
|
|||||||
query.OrderBy(orderField.DbColumnName);
|
query.OrderBy(orderField.DbColumnName);
|
||||||
IEnumerable recordsTmp = (IEnumerable)query.ToList();
|
IEnumerable recordsTmp = (IEnumerable)query.ToList();
|
||||||
List<dynamic> records = recordsTmp.ToDynamicList();
|
List<dynamic> records = recordsTmp.ToDynamicList();
|
||||||
//这里要过滤已存在的数据
|
// 过滤已存在的数据
|
||||||
if (input.FilterExistingData && records.Count() > 0)
|
if (input.FilterExistingData && records.Count() > 0)
|
||||||
{
|
{
|
||||||
//获取实体类型
|
// 获取实体类型
|
||||||
//获取所有种数据数据类型
|
|
||||||
var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false) && u.FullName.EndsWith("." + input.EntityName))
|
var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false) && u.FullName.EndsWith("." + input.EntityName))
|
||||||
.Where(u => !u.GetCustomAttributes<IgnoreTableAttribute>().Any())
|
.Where(u => !u.GetCustomAttributes<IgnoreTableAttribute>().Any()).ToList();
|
||||||
.ToList();
|
// 只有一个实体匹配才能过滤
|
||||||
if (entityTypes.Count == 1) //只有一个实体匹配才能过滤
|
if (entityTypes.Count == 1)
|
||||||
{
|
{
|
||||||
//获取实体的主键对应的属性名称
|
// 获取实体的主键对应的属性名称
|
||||||
var pkInfo = entityTypes[0].GetProperties().Where(u => u.GetCustomAttribute<SugarColumn>() != null && u.GetCustomAttribute<SugarColumn>().IsPrimaryKey).First();
|
var pkInfo = entityTypes[0].GetProperties().Where(u => u.GetCustomAttribute<SugarColumn>() != null && u.GetCustomAttribute<SugarColumn>().IsPrimaryKey).First();
|
||||||
if (pkInfo != null)
|
if (pkInfo != null)
|
||||||
{
|
{
|
||||||
var seedDataTypes = App.EffectiveTypes
|
var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass
|
||||||
.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(
|
&& u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>)) && i.GenericTypeArguments[0] == entityTypes[0])).ToList();
|
||||||
i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>)) && i.GenericTypeArguments[0] == entityTypes[0]
|
// 可能会重名的种子数据不作为过滤项
|
||||||
)
|
|
||||||
)
|
|
||||||
.ToList();
|
|
||||||
//可能会重名的种子数据不作为过滤项
|
|
||||||
string doNotFilterfullName1 = $"{input.Position}.SeedData.{input.SeedDataName}";
|
string doNotFilterfullName1 = $"{input.Position}.SeedData.{input.SeedDataName}";
|
||||||
string doNotFilterfullName2 = $"{input.Position}.{input.SeedDataName}"; //Core中的命名空间没有SeedData
|
string doNotFilterfullName2 = $"{input.Position}.{input.SeedDataName}"; // Core中的命名空间没有SeedData
|
||||||
|
|
||||||
PropertyInfo idPropertySeedData = records[0].GetType().GetProperty("Id");
|
PropertyInfo idPropertySeedData = records[0].GetType().GetProperty("Id");
|
||||||
|
|
||||||
@ -389,13 +382,13 @@ public class SysDatabaseService : IDynamicApiController, ITransient
|
|||||||
string fullName = seedDataTypes[i].FullName;
|
string fullName = seedDataTypes[i].FullName;
|
||||||
if ((fullName == doNotFilterfullName1) || (fullName == doNotFilterfullName2))
|
if ((fullName == doNotFilterfullName1) || (fullName == doNotFilterfullName2))
|
||||||
continue;
|
continue;
|
||||||
//开始删除重复数据
|
// 开始删除重复数据
|
||||||
var instance = Activator.CreateInstance(seedDataTypes[i]);
|
var instance = Activator.CreateInstance(seedDataTypes[i]);
|
||||||
var hasDataMethod = seedDataTypes[i].GetMethod("HasData");
|
var hasDataMethod = seedDataTypes[i].GetMethod("HasData");
|
||||||
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>();
|
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>();
|
||||||
if (seedData == null) continue;
|
if (seedData == null) continue;
|
||||||
|
|
||||||
List<object> recordsToRemove = new List<object>();
|
var recordsToRemove = new List<object>();
|
||||||
foreach (var record in records)
|
foreach (var record in records)
|
||||||
{
|
{
|
||||||
object recordId = pkInfo.GetValue(record);
|
object recordId = pkInfo.GetValue(record);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591</NoWarn>
|
<NoWarn>1701;1702;1591</NoWarn>
|
||||||
<DocumentationFile></DocumentationFile>
|
<DocumentationFile></DocumentationFile>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.16" />
|
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.16" />
|
||||||
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
|
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="9.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,281 +1,281 @@
|
|||||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||||
//
|
//
|
||||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||||
//
|
//
|
||||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||||
|
|
||||||
using Admin.NET.Core;
|
using Admin.NET.Core;
|
||||||
using Admin.NET.Core.Service;
|
using Admin.NET.Core.Service;
|
||||||
using AspNetCoreRateLimit;
|
using AspNetCoreRateLimit;
|
||||||
using Furion;
|
using Furion;
|
||||||
using Furion.Logging;
|
using Furion.Logging;
|
||||||
using Furion.SpecificationDocument;
|
using Furion.SpecificationDocument;
|
||||||
using Furion.VirtualFileServer;
|
using Furion.VirtualFileServer;
|
||||||
using IGeekFan.AspNetCore.Knife4jUI;
|
using IGeekFan.AspNetCore.Knife4jUI;
|
||||||
using IPTools.Core;
|
using IPTools.Core;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.AspNetCore.ResponseCompression;
|
using Microsoft.AspNetCore.ResponseCompression;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using OnceMi.AspNetCore.OSS;
|
using OnceMi.AspNetCore.OSS;
|
||||||
using SixLabors.ImageSharp.Web.DependencyInjection;
|
using SixLabors.ImageSharp.Web.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Unicode;
|
using System.Text.Unicode;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Admin.NET.Web.Core;
|
namespace Admin.NET.Web.Core;
|
||||||
|
|
||||||
[AppStartup(int.MaxValue)]
|
[AppStartup(int.MaxValue)]
|
||||||
public class Startup : AppStartup
|
public class Startup : AppStartup
|
||||||
{
|
{
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
// 配置选项
|
// 配置选项
|
||||||
services.AddProjectOptions();
|
services.AddProjectOptions();
|
||||||
|
|
||||||
// 缓存注册
|
// 缓存注册
|
||||||
services.AddCache();
|
services.AddCache();
|
||||||
// SqlSugar
|
// SqlSugar
|
||||||
services.AddSqlSugar();
|
services.AddSqlSugar();
|
||||||
// JWT
|
// JWT
|
||||||
services.AddJwt<JwtHandler>(enableGlobalAuthorize: true, jwtBearerConfigure: options =>
|
services.AddJwt<JwtHandler>(enableGlobalAuthorize: true, jwtBearerConfigure: options =>
|
||||||
{
|
{
|
||||||
// 实现 JWT 身份验证过程控制
|
// 实现 JWT 身份验证过程控制
|
||||||
options.Events = new JwtBearerEvents
|
options.Events = new JwtBearerEvents
|
||||||
{
|
{
|
||||||
OnMessageReceived = context =>
|
OnMessageReceived = context =>
|
||||||
{
|
{
|
||||||
var httpContext = context.HttpContext;
|
var httpContext = context.HttpContext;
|
||||||
// 若请求 Url 包含 token 参数,则设置 Token 值
|
// 若请求 Url 包含 token 参数,则设置 Token 值
|
||||||
if (httpContext.Request.Query.ContainsKey("token"))
|
if (httpContext.Request.Query.ContainsKey("token"))
|
||||||
context.Token = httpContext.Request.Query["token"];
|
context.Token = httpContext.Request.Query["token"];
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}).AddSignatureAuthentication(options => // 添加 Signature 身份验证
|
}).AddSignatureAuthentication(options => // 添加 Signature 身份验证
|
||||||
{
|
{
|
||||||
options.Events = SysOpenAccessService.GetSignatureAuthenticationEventImpl();
|
options.Events = SysOpenAccessService.GetSignatureAuthenticationEventImpl();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 允许跨域
|
// 允许跨域
|
||||||
services.AddCorsAccessor();
|
services.AddCorsAccessor();
|
||||||
// 远程请求
|
// 远程请求
|
||||||
services.AddRemoteRequest();
|
services.AddRemoteRequest();
|
||||||
// 任务队列
|
// 任务队列
|
||||||
services.AddTaskQueue();
|
services.AddTaskQueue();
|
||||||
// 作业调度
|
// 作业调度
|
||||||
services.AddSchedule(options =>
|
services.AddSchedule(options =>
|
||||||
{
|
{
|
||||||
if (App.GetConfig<bool>("JobSchedule:Enabled", true))
|
if (App.GetConfig<bool>("JobSchedule:Enabled", true))
|
||||||
{
|
{
|
||||||
options.AddPersistence<DbJobPersistence>(); // 添加作业持久化器
|
options.AddPersistence<DbJobPersistence>(); // 添加作业持久化器
|
||||||
options.AddMonitor<JobMonitor>(); // 添加作业执行监视器
|
options.AddMonitor<JobMonitor>(); // 添加作业执行监视器
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 脱敏检测
|
// 脱敏检测
|
||||||
services.AddSensitiveDetection();
|
services.AddSensitiveDetection();
|
||||||
|
|
||||||
// Json序列化设置
|
// Json序列化设置
|
||||||
static void SetNewtonsoftJsonSetting(JsonSerializerSettings setting)
|
static void SetNewtonsoftJsonSetting(JsonSerializerSettings setting)
|
||||||
{
|
{
|
||||||
setting.DateFormatHandling = DateFormatHandling.IsoDateFormat;
|
setting.DateFormatHandling = DateFormatHandling.IsoDateFormat;
|
||||||
setting.DateTimeZoneHandling = DateTimeZoneHandling.Local;
|
setting.DateTimeZoneHandling = DateTimeZoneHandling.Local;
|
||||||
// setting.Converters.AddDateTimeTypeConverters(localized: true); // 时间本地化
|
// setting.Converters.AddDateTimeTypeConverters(localized: true); // 时间本地化
|
||||||
setting.DateFormatString = "yyyy-MM-dd HH:mm:ss"; // 时间格式化
|
setting.DateFormatString = "yyyy-MM-dd HH:mm:ss"; // 时间格式化
|
||||||
setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // 忽略循环引用
|
setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // 忽略循环引用
|
||||||
// setting.ContractResolver = new CamelCasePropertyNamesContractResolver(); // 解决动态对象属性名大写
|
// setting.ContractResolver = new CamelCasePropertyNamesContractResolver(); // 解决动态对象属性名大写
|
||||||
// setting.NullValueHandling = NullValueHandling.Ignore; // 忽略空值
|
// setting.NullValueHandling = NullValueHandling.Ignore; // 忽略空值
|
||||||
// setting.Converters.AddLongTypeConverters(); // long转string(防止js精度溢出) 超过17位开启
|
// setting.Converters.AddLongTypeConverters(); // long转string(防止js精度溢出) 超过17位开启
|
||||||
// setting.MetadataPropertyHandling = MetadataPropertyHandling.Ignore; // 解决DateTimeOffset异常
|
// setting.MetadataPropertyHandling = MetadataPropertyHandling.Ignore; // 解决DateTimeOffset异常
|
||||||
// setting.DateParseHandling = DateParseHandling.None; // 解决DateTimeOffset异常
|
// setting.DateParseHandling = DateParseHandling.None; // 解决DateTimeOffset异常
|
||||||
// setting.Converters.Add(new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }); // 解决DateTimeOffset异常
|
// setting.Converters.Add(new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }); // 解决DateTimeOffset异常
|
||||||
};
|
};
|
||||||
|
|
||||||
services.AddControllersWithViews()
|
services.AddControllersWithViews()
|
||||||
.AddAppLocalization()
|
.AddAppLocalization()
|
||||||
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
|
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
|
||||||
//.AddXmlSerializerFormatters()
|
//.AddXmlSerializerFormatters()
|
||||||
//.AddXmlDataContractSerializerFormatters()
|
//.AddXmlDataContractSerializerFormatters()
|
||||||
.AddInjectWithUnifyResult<AdminResultProvider>()
|
.AddInjectWithUnifyResult<AdminResultProvider>()
|
||||||
.AddJsonOptions(options =>
|
.AddJsonOptions(options =>
|
||||||
{
|
{
|
||||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); // 禁止Unicode转码
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); // 禁止Unicode转码
|
||||||
});
|
});
|
||||||
|
|
||||||
// 三方授权登录OAuth
|
// 三方授权登录OAuth
|
||||||
services.AddOAuth();
|
services.AddOAuth();
|
||||||
|
|
||||||
// ElasticSearch
|
// ElasticSearch
|
||||||
services.AddElasticSearch();
|
services.AddElasticSearch();
|
||||||
|
|
||||||
// 配置Nginx转发获取客户端真实IP
|
// 配置Nginx转发获取客户端真实IP
|
||||||
// 注1:如果负载均衡不是在本机通过 Loopback 地址转发请求的,一定要加上options.KnownNetworks.Clear()和options.KnownProxies.Clear()
|
// 注1:如果负载均衡不是在本机通过 Loopback 地址转发请求的,一定要加上options.KnownNetworks.Clear()和options.KnownProxies.Clear()
|
||||||
// 注2:如果设置环境变量 ASPNETCORE_FORWARDEDHEADERS_ENABLED 为 True,则不需要下面的配置代码
|
// 注2:如果设置环境变量 ASPNETCORE_FORWARDEDHEADERS_ENABLED 为 True,则不需要下面的配置代码
|
||||||
services.Configure<ForwardedHeadersOptions>(options =>
|
services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
{
|
{
|
||||||
options.ForwardedHeaders = ForwardedHeaders.All;
|
options.ForwardedHeaders = ForwardedHeaders.All;
|
||||||
options.KnownNetworks.Clear();
|
options.KnownNetworks.Clear();
|
||||||
options.KnownProxies.Clear();
|
options.KnownProxies.Clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 限流服务
|
// 限流服务
|
||||||
services.AddInMemoryRateLimiting();
|
services.AddInMemoryRateLimiting();
|
||||||
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
|
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
|
||||||
|
|
||||||
// 事件总线
|
// 事件总线
|
||||||
services.AddEventBus(options =>
|
services.AddEventBus(options =>
|
||||||
{
|
{
|
||||||
options.UseUtcTimestamp = false;
|
options.UseUtcTimestamp = false;
|
||||||
// 不启用事件日志
|
// 不启用事件日志
|
||||||
options.LogEnabled = false;
|
options.LogEnabled = false;
|
||||||
// 事件执行器(失败重试)
|
// 事件执行器(失败重试)
|
||||||
options.AddExecutor<RetryEventHandlerExecutor>();
|
options.AddExecutor<RetryEventHandlerExecutor>();
|
||||||
// 事件执行器(重试后依然处理未处理异常的处理器)
|
// 事件执行器(重试后依然处理未处理异常的处理器)
|
||||||
options.UnobservedTaskExceptionHandler = (obj, args) =>
|
options.UnobservedTaskExceptionHandler = (obj, args) =>
|
||||||
{
|
{
|
||||||
if (args.Exception?.Message != null)
|
if (args.Exception?.Message != null)
|
||||||
Log.Error($"EeventBus 有未处理异常 :{args.Exception?.Message} ", args.Exception);
|
Log.Error($"EeventBus 有未处理异常 :{args.Exception?.Message} ", args.Exception);
|
||||||
};
|
};
|
||||||
// 事件执行器-监视器(每一次处理都会进入)
|
// 事件执行器-监视器(每一次处理都会进入)
|
||||||
options.AddMonitor<EventHandlerMonitor>();
|
options.AddMonitor<EventHandlerMonitor>();
|
||||||
|
|
||||||
#region Redis消息队列
|
#region Redis消息队列
|
||||||
|
|
||||||
// 替换事件源存储器为Redis
|
// 替换事件源存储器为Redis
|
||||||
var cacheOptions = App.GetConfig<CacheOptions>("Cache", true);
|
var cacheOptions = App.GetConfig<CacheOptions>("Cache", true);
|
||||||
if (cacheOptions.CacheType == CacheTypeEnum.Redis.ToString())
|
if (cacheOptions.CacheType == CacheTypeEnum.Redis.ToString())
|
||||||
{
|
{
|
||||||
options.ReplaceStorer(serviceProvider =>
|
options.ReplaceStorer(serviceProvider =>
|
||||||
{
|
{
|
||||||
var cacheProvider = serviceProvider.GetRequiredService<NewLife.Caching.ICacheProvider>();
|
var cacheProvider = serviceProvider.GetRequiredService<NewLife.Caching.ICacheProvider>();
|
||||||
// 创建默认内存通道事件源对象,可自定义队列路由key,如:adminnet_eventsource_queue
|
// 创建默认内存通道事件源对象,可自定义队列路由key,如:adminnet_eventsource_queue
|
||||||
return new RedisEventSourceStorer(cacheProvider, "adminnet_eventsource_queue", 3000);
|
return new RedisEventSourceStorer(cacheProvider, "adminnet_eventsource_queue", 3000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Redis消息队列
|
#endregion Redis消息队列
|
||||||
|
|
||||||
#region RabbitMQ消息队列
|
#region RabbitMQ消息队列
|
||||||
|
|
||||||
//// 创建默认内存通道事件源对象,可自定义队列路由key,如:adminnet
|
//// 创建默认内存通道事件源对象,可自定义队列路由key,如:adminnet
|
||||||
//var eventBusOpt = App.GetConfig<EventBusOptions>("EventBus", true);
|
//var eventBusOpt = App.GetConfig<EventBusOptions>("EventBus", true);
|
||||||
//var rbmqEventSourceStorer = new RabbitMQEventSourceStore(new ConnectionFactory
|
//var rbmqEventSourceStorer = new RabbitMQEventSourceStore(new ConnectionFactory
|
||||||
//{
|
//{
|
||||||
// UserName = eventBusOpt.RabbitMQ.UserName,
|
// UserName = eventBusOpt.RabbitMQ.UserName,
|
||||||
// Password = eventBusOpt.RabbitMQ.Password,
|
// Password = eventBusOpt.RabbitMQ.Password,
|
||||||
// HostName = eventBusOpt.RabbitMQ.HostName,
|
// HostName = eventBusOpt.RabbitMQ.HostName,
|
||||||
// Port = eventBusOpt.RabbitMQ.Port
|
// Port = eventBusOpt.RabbitMQ.Port
|
||||||
//}, "adminnet", 3000);
|
//}, "adminnet", 3000);
|
||||||
|
|
||||||
//// 替换默认事件总线存储器
|
//// 替换默认事件总线存储器
|
||||||
//options.ReplaceStorer(serviceProvider =>
|
//options.ReplaceStorer(serviceProvider =>
|
||||||
//{
|
//{
|
||||||
// return rbmqEventSourceStorer;
|
// return rbmqEventSourceStorer;
|
||||||
//});
|
//});
|
||||||
|
|
||||||
#endregion RabbitMQ消息队列
|
#endregion RabbitMQ消息队列
|
||||||
});
|
});
|
||||||
|
|
||||||
// 图像处理
|
// 图像处理
|
||||||
services.AddImageSharp();
|
services.AddImageSharp();
|
||||||
|
|
||||||
// OSS对象存储
|
// OSS对象存储
|
||||||
var ossOpt = App.GetConfig<OSSProviderOptions>("OSSProvider", true);
|
var ossOpt = App.GetConfig<OSSProviderOptions>("OSSProvider", true);
|
||||||
services.AddOSSService(Enum.GetName(ossOpt.Provider), "OSSProvider");
|
services.AddOSSService(Enum.GetName(ossOpt.Provider), "OSSProvider");
|
||||||
|
|
||||||
// 模板引擎
|
// 模板引擎
|
||||||
services.AddViewEngine();
|
services.AddViewEngine();
|
||||||
|
|
||||||
// 即时通讯
|
// 即时通讯
|
||||||
services.AddSignalR(options =>
|
services.AddSignalR(options =>
|
||||||
{
|
{
|
||||||
options.EnableDetailedErrors = true;
|
options.EnableDetailedErrors = true;
|
||||||
options.KeepAliveInterval = TimeSpan.FromSeconds(15); // 服务器端向客户端ping的间隔
|
options.KeepAliveInterval = TimeSpan.FromSeconds(15); // 服务器端向客户端ping的间隔
|
||||||
options.ClientTimeoutInterval = TimeSpan.FromSeconds(30); // 客户端向服务器端ping的间隔
|
options.ClientTimeoutInterval = TimeSpan.FromSeconds(30); // 客户端向服务器端ping的间隔
|
||||||
options.MaximumReceiveMessageSize = 1024 * 1014 * 10; // 数据包大小10M,默认最大为32K
|
options.MaximumReceiveMessageSize = 1024 * 1014 * 10; // 数据包大小10M,默认最大为32K
|
||||||
}).AddNewtonsoftJsonProtocol(options => SetNewtonsoftJsonSetting(options.PayloadSerializerSettings));
|
}).AddNewtonsoftJsonProtocol(options => SetNewtonsoftJsonSetting(options.PayloadSerializerSettings));
|
||||||
|
|
||||||
// 系统日志
|
// 系统日志
|
||||||
services.AddLoggingSetup();
|
services.AddLoggingSetup();
|
||||||
|
|
||||||
// 验证码
|
// 验证码
|
||||||
services.AddCaptcha();
|
services.AddCaptcha();
|
||||||
|
|
||||||
// 控制台logo
|
// 控制台logo
|
||||||
services.AddConsoleLogo();
|
services.AddConsoleLogo();
|
||||||
|
|
||||||
// 将IP地址数据库文件完全加载到内存,提升查询速度(以空间换时间,内存将会增加60-70M)
|
// 将IP地址数据库文件完全加载到内存,提升查询速度(以空间换时间,内存将会增加60-70M)
|
||||||
IpToolSettings.LoadInternationalDbToMemory = true;
|
IpToolSettings.LoadInternationalDbToMemory = true;
|
||||||
// 设置默认查询器China和International
|
// 设置默认查询器China和International
|
||||||
//IpToolSettings.DefalutSearcherType = IpSearcherType.China;
|
//IpToolSettings.DefalutSearcherType = IpSearcherType.China;
|
||||||
IpToolSettings.DefalutSearcherType = IpSearcherType.International;
|
IpToolSettings.DefalutSearcherType = IpSearcherType.International;
|
||||||
|
|
||||||
// 配置gzip与br的压缩等级为最优
|
// 配置gzip与br的压缩等级为最优
|
||||||
//services.Configure<BrotliCompressionProviderOptions>(options =>
|
//services.Configure<BrotliCompressionProviderOptions>(options =>
|
||||||
//{
|
//{
|
||||||
// options.Level = CompressionLevel.Optimal;
|
// options.Level = CompressionLevel.Optimal;
|
||||||
//});
|
//});
|
||||||
//services.Configure<GzipCompressionProviderOptions>(options =>
|
//services.Configure<GzipCompressionProviderOptions>(options =>
|
||||||
//{
|
//{
|
||||||
// options.Level = CompressionLevel.Optimal;
|
// options.Level = CompressionLevel.Optimal;
|
||||||
//});
|
//});
|
||||||
// 注册压缩响应
|
// 注册压缩响应
|
||||||
services.AddResponseCompression((options) =>
|
services.AddResponseCompression((options) =>
|
||||||
{
|
{
|
||||||
options.EnableForHttps = true;
|
options.EnableForHttps = true;
|
||||||
options.Providers.Add<BrotliCompressionProvider>();
|
options.Providers.Add<BrotliCompressionProvider>();
|
||||||
options.Providers.Add<GzipCompressionProvider>();
|
options.Providers.Add<GzipCompressionProvider>();
|
||||||
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
|
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
|
||||||
{
|
{
|
||||||
"text/html; charset=utf-8",
|
"text/html; charset=utf-8",
|
||||||
"application/xhtml+xml",
|
"application/xhtml+xml",
|
||||||
"application/atom+xml",
|
"application/atom+xml",
|
||||||
"image/svg+xml"
|
"image/svg+xml"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 注册虚拟文件系统服务
|
// 注册虚拟文件系统服务
|
||||||
services.AddVirtualFileServer();
|
services.AddVirtualFileServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
// 响应压缩
|
// 响应压缩
|
||||||
app.UseResponseCompression();
|
app.UseResponseCompression();
|
||||||
|
|
||||||
app.UseForwardedHeaders();
|
app.UseForwardedHeaders();
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Home/Error");
|
app.UseExceptionHandler("/Home/Error");
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Use(async (context, next) =>
|
app.Use(async (context, next) =>
|
||||||
{
|
{
|
||||||
context.Response.Headers.Append("Admin.NET", "Admin.NET");
|
context.Response.Headers.Append("Admin.NET", "Admin.NET");
|
||||||
await next();
|
await next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 图像处理
|
// 图像处理
|
||||||
app.UseImageSharp();
|
app.UseImageSharp();
|
||||||
|
|
||||||
// 特定文件类型(文件后缀)处理
|
// 特定文件类型(文件后缀)处理
|
||||||
var contentTypeProvider = FS.GetFileExtensionContentTypeProvider();
|
var contentTypeProvider = FS.GetFileExtensionContentTypeProvider();
|
||||||
// contentTypeProvider.Mappings[".文件后缀"] = "MIME 类型";
|
// contentTypeProvider.Mappings[".文件后缀"] = "MIME 类型";
|
||||||
var cpMappings = App.GetConfig<Dictionary<string, string>>("StaticContentTypeMappings");
|
var cpMappings = App.GetConfig<Dictionary<string, string>>("StaticContentTypeMappings");
|
||||||
if (cpMappings != null)
|
if (cpMappings != null)
|
||||||
@ -285,18 +285,16 @@ public class Startup : AppStartup
|
|||||||
app.UseStaticFiles(new StaticFileOptions
|
app.UseStaticFiles(new StaticFileOptions
|
||||||
{
|
{
|
||||||
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "wwwroot")),
|
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "wwwroot")),
|
||||||
//RequestPath = "/static",
|
// RequestPath = "/static",
|
||||||
ServeUnknownFileTypes = true, // 允许服务未知文件类型,以便能处理.dll这种非默认的静态文件类型
|
ServeUnknownFileTypes = true, // 允许服务未知文件类型,以便能处理.dll这种非默认的静态文件类型
|
||||||
//DefaultContentType = "application/octet-stream" // 为未知文件类型设置一个通用的内容类型
|
// DefaultContentType = "application/octet-stream" // 为未知文件类型设置一个通用的内容类型
|
||||||
DefaultContentType = cpMappings[".*"]
|
DefaultContentType = cpMappings[".*"]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var key in cpMappings.Keys)
|
foreach (var key in cpMappings.Keys)
|
||||||
{
|
|
||||||
contentTypeProvider.Mappings[key] = cpMappings[key];
|
contentTypeProvider.Mappings[key] = cpMappings[key];
|
||||||
}
|
|
||||||
app.UseStaticFiles(new StaticFileOptions
|
app.UseStaticFiles(new StaticFileOptions
|
||||||
{
|
{
|
||||||
ContentTypeProvider = contentTypeProvider
|
ContentTypeProvider = contentTypeProvider
|
||||||
@ -311,70 +309,69 @@ public class Startup : AppStartup
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// 启用HTTPS
|
//// 启用HTTPS
|
||||||
//app.UseHttpsRedirection();
|
//app.UseHttpsRedirection();
|
||||||
|
|
||||||
// 启用OAuth
|
// 启用OAuth
|
||||||
app.UseOAuth();
|
app.UseOAuth();
|
||||||
|
|
||||||
// 添加状态码拦截中间件
|
// 添加状态码拦截中间件
|
||||||
app.UseUnifyResultStatusCodes();
|
app.UseUnifyResultStatusCodes();
|
||||||
|
|
||||||
// 启用多语言,必须在 UseRouting 之前
|
// 启用多语言,必须在 UseRouting 之前
|
||||||
app.UseAppLocalization();
|
app.UseAppLocalization();
|
||||||
|
|
||||||
// 路由注册
|
// 路由注册
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
// 启用跨域,必须在 UseRouting 和 UseAuthentication 之间注册
|
// 启用跨域,必须在 UseRouting 和 UseAuthentication 之间注册
|
||||||
app.UseCorsAccessor();
|
app.UseCorsAccessor();
|
||||||
|
|
||||||
// 启用鉴权授权
|
// 启用鉴权授权
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
// 限流组件(在跨域之后)
|
// 限流组件(在跨域之后)
|
||||||
app.UseIpRateLimiting();
|
app.UseIpRateLimiting();
|
||||||
app.UseClientRateLimiting();
|
app.UseClientRateLimiting();
|
||||||
app.UsePolicyRateLimit();
|
app.UsePolicyRateLimit();
|
||||||
|
|
||||||
// 任务调度看板
|
// 任务调度看板
|
||||||
app.UseScheduleUI(options =>
|
app.UseScheduleUI(options =>
|
||||||
{
|
{
|
||||||
options.RequestPath = "/schedule"; // 必须以 / 开头且不以 / 结尾
|
options.RequestPath = "/schedule"; // 必须以 / 开头且不以 / 结尾
|
||||||
options.DisableOnProduction = true; // 生产环境关闭
|
options.DisableOnProduction = true; // 生产环境关闭
|
||||||
options.DisplayEmptyTriggerJobs = true; // 是否显示空作业触发器的作业
|
options.DisplayEmptyTriggerJobs = true; // 是否显示空作业触发器的作业
|
||||||
options.DisplayHead = false; // 是否显示页头
|
options.DisplayHead = false; // 是否显示页头
|
||||||
options.DefaultExpandAllJobs = false; // 是否默认展开所有作业
|
options.DefaultExpandAllJobs = false; // 是否默认展开所有作业
|
||||||
});
|
});
|
||||||
|
|
||||||
// 配置Swagger-Knife4UI(路由前缀一致代表独立,不同则代表共存)
|
// 配置Swagger-Knife4UI(路由前缀一致代表独立,不同则代表共存)
|
||||||
app.UseKnife4UI(options =>
|
app.UseKnife4UI(options =>
|
||||||
{
|
{
|
||||||
options.RoutePrefix = "kapi";
|
options.RoutePrefix = "kapi";
|
||||||
foreach (var groupInfo in SpecificationDocumentBuilder.GetOpenApiGroups())
|
foreach (var groupInfo in SpecificationDocumentBuilder.GetOpenApiGroups())
|
||||||
{
|
{
|
||||||
options.SwaggerEndpoint("/" + groupInfo.RouteTemplate, groupInfo.Title);
|
options.SwaggerEndpoint("/" + groupInfo.RouteTemplate, groupInfo.Title);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseInject(string.Empty, options =>
|
app.UseInject(string.Empty, options =>
|
||||||
{
|
{
|
||||||
foreach (var groupInfo in SpecificationDocumentBuilder.GetOpenApiGroups())
|
foreach (var groupInfo in SpecificationDocumentBuilder.GetOpenApiGroups())
|
||||||
{
|
{
|
||||||
groupInfo.Description += "<br/><u><b><font color='FF0000'> 👮不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!</font></b></u>";
|
groupInfo.Description += "<br/><u><b><font color='FF0000'> 👮不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!</font></b></u>";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
// 注册集线器
|
// 注册集线器
|
||||||
endpoints.MapHubs();
|
endpoints.MapHubs();
|
||||||
|
|
||||||
endpoints.MapControllerRoute(
|
endpoints.MapControllerRoute(
|
||||||
name: "default",
|
name: "default",
|
||||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
|
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
|
||||||
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
|
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591;8632</NoWarn>
|
<NoWarn>1701;1702;1591;8632</NoWarn>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591;8632</NoWarn>
|
<NoWarn>1701;1702;1591;8632</NoWarn>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591;8632</NoWarn>
|
<NoWarn>1701;1702;1591;8632</NoWarn>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591;8632</NoWarn>
|
<NoWarn>1701;1702;1591;8632</NoWarn>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591;8632</NoWarn>
|
<NoWarn>1701;1702;1591;8632</NoWarn>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||||
<NoWarn>1701;1702;1591;8632</NoWarn>
|
<NoWarn>1701;1702;1591;8632</NoWarn>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user