gpt4 book ai didi

asp.net-web-api - 如何让 ASP.NET Web API(自托管)监听 *only* localhost?

转载 作者:行者123 更新时间:2023-12-03 20:52:34 25 4
gpt4 key购买 nike

我按照示例 here对于自托管的 ASP.NET Web API 服务。但是,当在基地址中指定“localhost”作为主机时,它会被翻译为“+”(意思是“所有可用”)。

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();
}

我真的希望我的主机只绑定(bind)到“localhost”——它只能从同一台机器访问,而且我不想弄乱 URL ACL。

如何配置 Web API 以不将“localhost”重写为“+”?

最佳答案

设置您的HostNameComparisonMode属性精确:

var config = new HttpSelfHostConfiguration("https://localhost/api/");
config.HostNameComparisonMode = HostNameComparisonMode.Exact;

this article有关 HostNameComparisonMode 的更多信息

关于asp.net-web-api - 如何让 ASP.NET Web API(自托管)监听 *only* localhost?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17260766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com