作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我按照示例 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();
}
最佳答案
设置您的HostNameComparisonMode
属性精确:
var config = new HttpSelfHostConfiguration("https://localhost/api/");
config.HostNameComparisonMode = HostNameComparisonMode.Exact;
关于asp.net-web-api - 如何让 ASP.NET Web API(自托管)监听 *only* localhost?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17260766/
我是一名优秀的程序员,十分优秀!