Web API自托管-在所有网络接口上绑定 [英] Web API self host - bind on all network interfaces
本文介绍了Web API自托管-在所有网络接口上绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使Web API自托管主机在所有网络接口上绑定?
How do you make a Web API self host bind on all network interfaces?
我目前有以下代码.不幸的是,它仅在本地主机上绑定.因此,无法从本地主机访问该服务器.
I have the below code currently. Unfortunately, it binds only on localhost. So access to this server from other than localhost is failing.
var baseAddress = string.Format("http://localhost:9000/");
using (WebApp.Start<Startup> (baseAddress))
{
Console.WriteLine("Server started");
Thread.Sleep(1000000);
}
推荐答案
只需像这样更改基址
var baseAddress = "http://*:9000/";
using (WebApp.Start<Startup> (baseAddress))
{
Console.WriteLine("Server started");
Thread.Sleep(1000000);
}
它应该正确地绑定到所有接口.
And it should bind correctlly to all interfaces.
这篇关于Web API自托管-在所有网络接口上绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文