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.

56 lines
1.5 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
  1. #if NETCORE
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Server.Kestrel.Core;
  4. using System.Net;
  5. namespace Apewer.Web
  6. {
  7. /// <summary>Kestrel 服务器。</summary>
  8. public class KestrelServer<TStartup> : KestrelServer where TStartup : AspNetCoreStartup
  9. {
  10. /// <summary>启动。</summary>
  11. public virtual void Run() => Run<TStartup>(false);
  12. }
  13. /// <summary>Kestrel 服务器。</summary>
  14. public class KestrelServer : AspNetCoreServer
  15. {
  16. /// <summary>配置 WebHost 构建程序。</summary>
  17. protected override void Configure(IWebHostBuilder builder)
  18. {
  19. builder.ConfigureKestrel((context, options) =>
  20. {
  21. Configure(options);
  22. });
  23. }
  24. /// <summary>配置 Kestrel 服务器。</summary>
  25. private void Configure(KestrelServerOptions options)
  26. {
  27. // 配置端口和证书。
  28. var certificate = Certificate;
  29. if (certificate == null) options.Listen(IPAddress.Any, Port);
  30. else options.Listen(IPAddress.Any, Port, (listen) =>
  31. {
  32. listen.UseHttps(certificate, (ao) =>
  33. {
  34. ao.CheckCertificateRevocation = false;
  35. ao.ServerCertificate = certificate;
  36. ao.AllowAnyClientCertificate();
  37. });
  38. });
  39. }
  40. /// <summary>启动。</summary>
  41. public override void Run<T>() => Run<T>(false);
  42. }
  43. }
  44. #endif