2015-11-19 8 views
5

Mit SslStream und Socket habe ich einen https-Webserver von Grund auf neu entwickelt. Ich kann ein Zertifikat für den Stream aus C# -Code anwenden und mit den Anforderungen umgehen.Owin Self-Host-Konsolenanwendung mit https-Unterstützung (keine Web-API, kein SignalR)

Allerdings habe ich nicht herausgefunden, wie dies mit Owin zu tun. Kann jemand ein Zertifikat an eine selbst gehostete Konsolenanwendung binden?

Beispiel:

// Bind the below certificate to Owin host 
var certificate = new X509Certificate2("server.pfx", "password"); 

verweist auf den bestehenden Owin Host Code unten für Details:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Microsoft.Owin.Hosting; 
using AppFunc = System.Func<System.Collections.Generic.IDictionary<string, object>, System.Threading.Tasks.Task>; 

namespace Owin.Startup 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      int port = 8888; 
      string url = $"http://localhost:{port}"; 
      using (WebApp.Start<Startup>(url)) 
      { 
       Console.WriteLine($"Hosted: {url}"); 
       Console.ReadLine(); 
      } 
     } 
    } 

    public class Startup 
    { 
     private IAppBuilder app; 
     public void Configuration(IAppBuilder app) 
     { 
#if DEBUG 
      app.UseErrorPage(); 
#endif 

      app.Use(new Func<AppFunc, AppFunc>(next => (async env => 
      { 
       Console.WriteLine("Begin Request"); 
       foreach (var i in env.Keys) 
       { 
        Console.WriteLine($"{i}\t={(env[i] == null ? "null" : env[i].ToString())}\t#\t{(env[i] == null ? "null" : env[i].GetType().FullName)}"); 
       } 
       if (next != null) 
       { 
        await next.Invoke(env); 
       } 
       else 
       { 
        Console.WriteLine("Process Complete"); 
       } 
       Console.WriteLine("End Request"); 
      }))); 

      app.UseWelcomePage("/"); 

      this.app = app; 
     } 


    } 

} 

Antwort

Verwandte Themen