#if NETCORE using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; using System.Net; namespace Apewer.Web { /// Kestrel 服务器。 public class KestrelServer : KestrelServer where TStartup : AspNetCoreStartup { /// 启动。 public virtual void Run() => Run(false); } /// Kestrel 服务器。 public class KestrelServer : AspNetCoreServer { /// 配置 WebHost 构建程序。 protected override void Configure(IWebHostBuilder builder) { builder.ConfigureKestrel((context, options) => { Configure(options); }); } /// 配置 Kestrel 服务器。 private void Configure(KestrelServerOptions options) { // 配置端口和证书。 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(); }); }); } /// 启动。 public override void Run() => Run(false); } } #endif