【问题标题】:System.Net.Sockets.SocketException: Could not resolve host - Self-hosted Nancy app on MonoSystem.Net.Sockets.SocketException:无法解析主机 - Mono 上的自托管 Nancy 应用程序
【发布时间】:2016-12-24 09:33:17
【问题描述】:

我的 Program.cs 中有以下代码,用于在 Mono 4.2.2 上启动一个自托管的 nancy 应用程序。

    public static void Main (string[] args)
    {           
        var uri = "";

        if(ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Production || ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Staging)
        {
            uri = string.Format("http://localhost:{0}", Environment.GetEnvironmentVariable("PORT").ToString());
        }
        else if(ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Development)
        {
            uri = string.Format("http://localhost:8888");
        }

        Console.WriteLine("Starting Reflect.Web application on " + uri);

        // initialize an instance of NancyHost
        var host = new NancyHost(new Uri(uri));
        host.Start();  // start hosting

        // check if we're running on mono
        if (Type.GetType("Mono.Runtime") != null)
        {
            // on mono, processes will usually run as daemons - this allows you to listen
            // for termination signals (ctrl+c, shutdown, etc) and finalize correctly
            UnixSignal.WaitAny(new[] {
                new UnixSignal(Signum.SIGINT),
                new UnixSignal(Signum.SIGTERM),
                new UnixSignal(Signum.SIGQUIT),
                new UnixSignal(Signum.SIGHUP)
            });
        }
        else
        {
            Console.ReadLine();
        }

        host.Stop();  // stop hosting
    }

这段代码运行了好几个月。刚刚开始出现这个错误:

System.Net.Sockets.SocketException: Could not resolve host '+'

在这一行:

host.Start();  // start hosting

我不知道我最近对任何依赖项进行了任何更新。

以前有人遇到过这种情况吗?为什么是“+”号?

【问题讨论】:

    标签: c# mono nancy


    【解决方案1】:

    + 可以是“URI 前缀字符串”的一部分,.NET 的 HttpListener(不确定 mono)用来确定它应该在哪里托管应用程序,请查看 HttpListener's Class remarks 了解更多信息:

    同样,要指定 HttpListener 接受发送到端口的所有请求,请将主机元素替换为“+”字符“https://+:8080”。 “*”和“+”字符可以出现在包含路径的前缀中。

    我的猜测是您的代码正在检查 ReflectConfiguration.CurrentEnviroment 并错过了您选择的案例。

    是否没有配置/存在环境?还是您不在生产、暂存或开发中?新建URI对象时uri的值是多少?

    【讨论】:

    • 谢谢。我的主机文件存在问题,但确实产生了错误。
    猜你喜欢
    • 2016-10-11
    • 1970-01-01
    • 2012-01-23
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多