c# - 错误响应,OWIN 服务器中的启动选项

标签 c# asp.net-web-api owin

我的 OWIN 自托管服务器出现一些问题。我正在尝试通过我的本地网络访问它。这意味着主机的 IP 地址将用于连接到服务器。糟糕的是,我收到一个错误的请求,无效的主机名。

我已经做了一些谷歌搜索,我找到了一个关于启动选项的可能解决方案:

StartOptions options = new StartOptions();
options.Urls.Add("http://localhost:9095");
options.Urls.Add("http://127.0.0.1:9095");
options.Urls.Add(string.Format("http://{0}:9095", Environment.MachineName));

现在我尝试实现它只是为了得到一个错误:

static void Main()
        {
            string baseAddress = "http://localhost:4004/";

            /*Render application
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FrontVorm());
            */
            // Start OWIN host 
            StartOptions options = new StartOptions();
            options.Urls.Add("http://localhost:4004");
            options.Urls.Add("http://127.0.0.1:4004");
            options.Urls.Add(string.Format("http://{0}:4004", Environment.MachineName));
            using (WebApp.Start<Program>(options))
            {

                // Create HttpCient and make a request to api/values 
                HttpClient client = new HttpClient();
            }
}

我最初是用 baseURL 做的,然后 (url : baseAdress) 用我的启动做的。但是现在我收到一个错误,我的服务器停止运行。

{"The following errors occurred while attempting to load the app.\r\n - No 'Configuration' method was found in class 'ServerTestApp.Program, ServerTestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.":""}

知道我做错了什么吗?

我原来的实现不起作用,因为我需要让其他设备也可以通过我的本地网络访问服务器。我认为实现这些 startupOptions 可能会起到作用。

我已经禁用了我的防火墙 :)

最佳答案

  1. 使用这个 Url 选项,其中 9095 是端口号

    options.Urls.Add("http://+:9095");

  2. 检查您的防火墙设置。端口 9095 应该可以访问。

关于c# - 错误响应,OWIN 服务器中的启动选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28454616/

相关文章:

c# - 将具有基本类型的列表序列化为派生类型 json

asp.net-web-api - VSTS 版本定义中的通配符

c# - 怀疑在 IAppBuilder.CreatePerOwinContext() 中注册的对象是否会被处置

asp.net-mvc - OwinMiddleware 不保留 .net 4.6 中的文化变化。*

使用 POSTMAN 客户端的 C# web API POST JSON 数据在 FromBody 中始终为 NULL

c# - MVC Razor 语法

c# - 为什么 xamarin 表单 ListView 中的组标题在 Release模式下不可见?

asp.net-web-api - 如何以字典的形式访问所有查询字符串参数

c# - Web API 2 Owin 刷新 token 不起作用并在其到期时间之前返回 invalid_grant

c# - 我的消息会被两次添加到队列中吗?