Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web API Self-Host both HTTPS and HTTP in single service?

I have a public self-hosted ASP.NET Web API service that exposes two controllers. One of them I would like to have accessible only via HTTPS, and the other I don't. Can this be done within a single service? If so, can you provide a few hints? It seems like I would need to register two base addresses, but I don't see how that's possible for a single service.

like image 847
Lee Grissom Avatar asked Jan 23 '13 16:01

Lee Grissom


People also ask

Can ASP Net Web API ability to both self hosting?

Self Hosting. You can host a Web API as separate process than ASP.NET. It means you can host a Web API in console application or windows service or OWIN or any other process that is managed by . NET framework.

Can ASP Net Web API ability to both self hosting in IIS?

ASP.NET Web API does not need to always be hosted in IIS. You can host them in a separate process by creating a host application. Such a self-hosting is typically done using a Console application or a Windows application.

Can ASP Net Web API ability to host self hosting and IIS hosting?

ASP.NET Web API does not require IIS. You can self-host a web API in your own host process. New applications should use OWIN to self-host Web API. See Use OWIN to Self-Host ASP.NET Web API 2.

Can we have multiple post method in Web API?

Similarly, you can add any number of POST, GET, PUT, DELETE methods in one controller.


1 Answers

You need to create two HttpServer instances, one for http and one for https. I've been trying to find out why this limitation exists because I know HttpListener can handle registering both for the same listener.

Anyway, if creating two HttpServer instances really doesn't work for you then you will need to look at the Katana project and the Microsoft.Owin.HttpListener. That does support multiple addresses but unfortunately the default Katana startup code doesn't! But I have it on good authority there is a way to customize the HttpListener on startup to make it possible.

like image 95
Darrel Miller Avatar answered Nov 03 '22 06:11

Darrel Miller