Huu*_*b S 2 c# asp.net-web-api owin
我的 OWIN selfhost 服务器出现一些问题。我正在尝试使其可以通过我的本地网络进行访问。这意味着主机的 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));
Run Code Online (Sandbox Code Playgroud)
现在我尝试实现它却出现错误:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我最初使用 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'.":""}
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?
我最初的实现不起作用,因为我也需要在其他设备上通过本地网络访问服务器。我认为实施这些startupOptions 可能会起到作用。
我已经禁用了我的防火墙:)
| 归档时间: |
|
| 查看次数: |
2082 次 |
| 最近记录: |