【问题标题】:ASP .NET core console application on CentOS server drops requestsCentOS 服务器上的 ASP .NET 核心控制台应用程序丢弃请求
【发布时间】: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


    【解决方案1】:

    我发现了问题。与 ASP .net 或 CentOS 无关。这是我们的防火墙(位于 vpn 后面),路由规则由端口 ex 的范围设置:从 ip1 端口 10000-10010 -> 到 ip2 端口 10000-10010。因此,如果在 ip1 端口 10001 上收到一条消息,我认为它会被发送到 ip2 端口 10001。但不,它被发送到范围内的随机端口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2018-06-28
      • 2020-08-01
      • 2020-02-18
      • 2019-09-26
      • 1970-01-01
      • 2018-05-14
      相关资源
      最近更新 更多