I'm following the example here for a self-hosted ASP.NET Web API service. However, when specifying "localhost" as the host in the base address, it is translated to "+" (meaning "all available").
var baseAddress = new Uri("http://localhost:13210");
var configuration = new HttpSelfHostConfiguration(baseAddress);
configuration.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new {id = RouteParameter.Optional});
using (var server = new HttpSelfHostServer(configuration))
{
server.OpenAsync().Wait();
stop.WaitOne();
server.CloseAsync().Wait();
}
I really do want my host bound to just "localhost" -- it will only be accessed from the same machine, and I don't want to mess around with URL ACLs.
How do I configure Web API to not rewrite "localhost" to "+"?
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.
ASP.NET Web API can be either be hosted in IIS or in a separate host process. The former approach is usually appropriate when the Web API is part of a web application and one or more web applications are going to consume it.
Set your HostNameComparisonMode
property to Exact:
var config = new HttpSelfHostConfiguration("https://localhost/api/");
config.HostNameComparisonMode = HostNameComparisonMode.Exact;
See this article for more information on HostNameComparisonMode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With