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

59 lines
1.7 KiB

#if NETCORE
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Net;
namespace Apewer.Web
{
/// <summary>Kestrel 服务器。</summary>
public class KestrelServer<TStartup> : KestrelServer where TStartup : AspNetCoreStartup
{
/// <summary>启动。</summary>
public virtual void Run() => Run<TStartup>(false);
}
/// <summary>Kestrel 服务器。</summary>
public class KestrelServer : AspNetCoreServer
{
/// <summary>配置 WebHost 构建程序。</summary>
protected override void Configure(IWebHostBuilder builder) => builder.ConfigureKestrel(Configure);
/// <summary>配置 Kestrel 服务器。</summary>
protected virtual void Configure(KestrelServerOptions options)
{
// 同步 IO。
options.AllowSynchronousIO = true;
// 限制请求大小。
options.Limits.MaxRequestBodySize = MaxBody;
// 在 Response 中不包含 Server 属性。
options.AddServerHeader = false;
// 配置端口和证书。
var certificate = Certificate;
if (certificate == null) options.Listen(IPAddress.Any, Port);
else options.Listen(IPAddress.Any, Port, (listen) =>
{
listen.UseHttps(certificate, (ao) =>
{
ao.CheckCertificateRevocation = false;
ao.ServerCertificate = certificate;
ao.AllowAnyClientCertificate();
});
});
}
/// <summary>启动。</summary>
public override void Run<T>() => Run<T>(false);
}
}
#endif