【发布时间】:2017-02-06 14:27:59
【问题描述】:
我有一个使用控制台运行 ASP .Net 核心的应用程序(不是 Web 应用程序,没有 IIS)。在 Windows 上,一切都一直运行良好。但是当我在我们的服务器(CentOS 7)上运行它时,大多数请求都会被丢弃。
我的开始方法是:
...
var config = new ConfigurationBuilder()
.AddCommandLine(new string[] { $"--server.urls={urls}" })
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseStartup<Listener>()
.UseLoggerFactory(loggerFactory)
.Build();
host.Start();
ConsoleKeyInfo key;
while ((key.Modifiers & ConsoleModifiers.Control) != ConsoleModifiers.Control && key.Key != ConsoleKey.Q)
{
key = Console.ReadKey();
}
host.Dispose();
还有监听器:
public class Listener
{
...
public void ConfigureServices(IServiceCollection collections)
{
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.Run(async (context) =>
{
...
context.Response.StatusCode = *** some response code ***
using (StreamWriter writer = new StreamWriter(context.Response.Body))
await writer.WriteLineAsync(*** a response ***);
});
}
}
如果用 curl 尝试一些请求
curl -v http://x.x.x.x:1234/
然后大部分时间我都会收到:
* timeout on name lookup is not supported
* Trying x.x.x.x...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* connect to x.x.x.x port 1234 failed: Connection refused
* Failed to connect to x.x.x.x port 1234: Connection refused
* Closing connection 0
curl: (7) Failed to connect to x.x.x.x port 1234: Connection refused
但仅在大多数情况下,这意味着同一命令有时会起作用。
而且,如果我使用 Postman,那么它可以工作 10 次中有 9 次..
我到处找,我真的很迷茫,如果有人有想法请告诉我。
【问题讨论】:
标签: c# asp.net linux centos .net-core