c# - Web API 自主机 - 在所有网络接口(interface)上绑定(bind)

标签 c# asp.net asp.net-web-api2 self-hosting

如何使 Web API self 主机绑定(bind)到所有网络接口(interface)?

我目前有以下代码。不幸的是,它只在本地主机上绑定(bind)。因此,从本地主机以外的地方访问此服务器失败。

var baseAddress = string.Format("http://localhost:9000/"); 
            using (WebApp.Start<Startup> (baseAddress)) 
            {
                Console.WriteLine("Server started");
                Thread.Sleep(1000000);
            }

最佳答案

像这样改 rebase 地址就可以了

        var baseAddress = "http://*:9000/"; 
        using (WebApp.Start<Startup> (baseAddress)) 
        {
            Console.WriteLine("Server started");
            Thread.Sleep(1000000);
        }

它应该正确地绑定(bind)到所有接口(interface)。

关于c# - Web API 自主机 - 在所有网络接口(interface)上绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26598042/

相关文章:

c# - 连接到另一台机器上的特定 SQL Server 实例

c# - 当我从下拉列表中选择一个值来解决网格中的值时,它会覆盖它

c# - Activator.CreateInstance(Type) 作为接口(interface)返回 null

asp.net - .net 中的全局化和本地化有什么区别?

javascript - 如何在单击 Asp.Net 按钮单击事件时显示弹出窗口

c# - 如何找到asp :Login LoginError error type

c# - OWIN 启动 : Entry point was not found

c# - 如何使用 Microsoft Fakes 引用具有自身通用参数的 stub ?

c# - 是否有可能获得网站的 swagger 文档的离线版本?

c# - REST API(ASP.NET Web API 2)最佳实践: How to return 1 - N items that are not one type but 3 related types?