You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
2.3 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
// 顶层语句Top-level statements
// .NET 6+ 开始允许不写传统的 Program.Main 方法,文件中的语句会直接作为程序入口执行。
// 这里通过 Furion 的 Serve.Run 启动整个 Web 应用。
Serve.Run(RunOptions.Default.AddWebComponent<WebComponent>());
public class WebComponent : IWebComponent
{
public void Load(WebApplicationBuilder builder, ComponentContext componentContext)
{
// WebApplicationBuilder 是 ASP.NET Core 的宿主构建器。
// 可以把它理解成“程序正式启动前的总配置对象”。
// 设置日志过滤:
// 这里把微软基础设施层的高频日志过滤掉,避免控制台被大量框架日志刷屏。
builder.Logging.AddFilter((provider, category, logLevel) =>
{
// Lambda 表达式 => 是 C# 里常见的匿名函数写法。
// category 表示日志分类名,通常类似命名空间。
return !new[] { "Microsoft.Hosting", "Microsoft.AspNetCore" }.Any(u => category.StartsWith(u)) && logLevel >= LogLevel.Information;
});
// 配置 Kestrel
// Kestrel 是 ASP.NET Core 自带的 Web 服务器。
// 这里统一调大超时时间,并取消请求体大小限制,适合文件上传和长连接场景。
builder.WebHost.ConfigureKestrel(u =>
{
u.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(30);
u.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(30);
// null 表示不限制请求体大小。
// 实际生产中是否开放,要结合上传场景和安全策略决定。
u.Limits.MaxRequestBodySize = null;
});
}
}