Owin self host console application with https support (no web api, no SignalR)

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Owin self host console application with https support (no web api, no SignalR)



With SslStream and socket, I've developed a https web server from scratch.
I can apply a certificate to the stream from C# code and deal with the requests.



However, I didn't figure out how to do this with Owin.
Does any one know how to bind a certificate to a self hosted console application?



Example:


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



Please refer to the existing Owin host code below for 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($"it=(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;









2 Answers
2



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





I tried this but got the connection reset issue. Can you help to check the code at the following url? Thanks. stackoverflow.com/questions/33820731/…
– mind1n
Nov 20 '15 at 7:43




Owin self hosting applications just need to bind to the proper URLs in code, while the certificate mappings should be done separately via Windows HTTP API.



netsh http show sslcert can show you the existing mappings, and Jexus Manager provides the UI.


netsh http show sslcert






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

ix7dS5CvORy,FBhFJL,g8,FZr4rYc1j6niI,7LpVbi5cjuS5 a3iB2,6fMsvPB1val,8,9,X O3ODsUp 0zuNQ1jFx
dzbLKrh,wQP4y,FK,c2AlD3 L 9bEgsPI8C,R,qt6LBHocV5XCKl4rxBMUqZjX4pvl5t tsATEtPxV3FxE D,ugirGzTWApUaECBSI,t

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3