Owns console app with https support (no web api, no SignalR)

With SslStream and socket, I developed an https server from scratch. I can apply the certificate to the stream from C # code and process the requests.

However, I did not understand how to do this with Owin. Does anyone know how to associate a certificate with the console application itself?

Example:

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

For more information, see the existing Owin host code below:

 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; } } } 
+10
source share
2 answers

It depends on the server. Here's how to do it with the HttpListener: http://katanaproject.codeplex.com/wikipage?title=Selfhosting&referringTitle=Documentation

0
source

Self-hosted applications just need to bind to the right URLs in the code, and certificate mappings should be done separately through the Windows HTTP API.

netsh http show sslcert can show you existing mappings, and Jexus Manager provides a user interface.

0
source

Source: https://habr.com/ru/post/1236297/


All Articles