Owin self host console application with https support (no web api, no SignalR)
up vote
10
down vote
favorite
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($"{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;
}
}
}
c# ssl asp.net-web-api owin self-hosting
add a comment |
up vote
10
down vote
favorite
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($"{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;
}
}
}
c# ssl asp.net-web-api owin self-hosting
add a comment |
up vote
10
down vote
favorite
up vote
10
down vote
favorite
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($"{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;
}
}
}
c# ssl asp.net-web-api owin self-hosting
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($"{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;
}
}
}
c# ssl asp.net-web-api owin self-hosting
c# ssl asp.net-web-api owin self-hosting
edited Jul 11 at 1:10
abatishchev
68.5k69259389
68.5k69259389
asked Nov 19 '15 at 7:36
mind1n
4861822
4861822
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
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
add a comment |
up vote
0
down vote
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.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
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
add a comment |
up vote
0
down vote
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
add a comment |
up vote
0
down vote
up vote
0
down vote
It depends on the server. Here's how to do it with HttpListener: http://katanaproject.codeplex.com/wikipage?title=Selfhosting&referringTitle=Documentation
It depends on the server. Here's how to do it with HttpListener: http://katanaproject.codeplex.com/wikipage?title=Selfhosting&referringTitle=Documentation
answered Nov 19 '15 at 23:13
Tratcher
4,8041729
4,8041729
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
add a comment |
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
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
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
add a comment |
up vote
0
down vote
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.
add a comment |
up vote
0
down vote
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.
add a comment |
up vote
0
down vote
up vote
0
down vote
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.
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.
answered Apr 21 at 4:21
Lex Li
41.1k66894
41.1k66894
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33797748%2fowin-self-host-console-application-with-https-support-no-web-api-no-signalr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown