Program.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.IO;
  2. using System.Net;
  3. using System.Reflection;
  4. using System.Security.Cryptography.X509Certificates;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.Extensions.FileProviders;
  8. using Microsoft.Extensions.Hosting;
  9. using Microsoft.Extensions.Logging;
  10. namespace WsFedSample
  11. {
  12. public class Program
  13. {
  14. public static Task Main(string[] args)
  15. {
  16. var host = new HostBuilder()
  17. .ConfigureWebHost(webHostBuilder =>
  18. {
  19. webHostBuilder
  20. .UseKestrel(options =>
  21. {
  22. options.Listen(IPAddress.Loopback, 44307, listenOptions =>
  23. {
  24. // Configure SSL
  25. var serverCertificate = LoadCertificate();
  26. listenOptions.UseHttps(serverCertificate);
  27. });
  28. })
  29. .UseContentRoot(Directory.GetCurrentDirectory())
  30. .UseIISIntegration()
  31. .UseStartup<Startup>();
  32. })
  33. .ConfigureLogging(factory =>
  34. {
  35. factory.AddConsole();
  36. factory.AddDebug();
  37. factory.AddFilter("Console", level => level >= LogLevel.Information);
  38. factory.AddFilter("Debug", level => level >= LogLevel.Information);
  39. })
  40. .Build();
  41. return host.RunAsync();
  42. }
  43. private static X509Certificate2 LoadCertificate()
  44. {
  45. var assembly = typeof(Startup).Assembly;
  46. var embeddedFileProvider = new EmbeddedFileProvider(assembly, "WsFedSample");
  47. var certificateFileInfo = embeddedFileProvider.GetFileInfo("compiler/resources/cert.pfx");
  48. using (var certificateStream = certificateFileInfo.CreateReadStream())
  49. {
  50. byte[] certificatePayload;
  51. using (var memoryStream = new MemoryStream())
  52. {
  53. certificateStream.CopyTo(memoryStream);
  54. certificatePayload = memoryStream.ToArray();
  55. }
  56. return new X509Certificate2(certificatePayload, "testPassword");
  57. }
  58. }
  59. }
  60. }