How do I remotely access self-hosted Nancy service?

后端 未结 2 1319
刺人心
刺人心 2021-01-14 12:50

I am creating a simple Windows service that hosts a Nancy instance to provide views of its internal data. Everything works as expected when using a browser on the local mach

相关标签:
2条回答
  • 2021-01-14 13:00

    This answer provided the clue I needed. https://stackoverflow.com/a/21364604/1139376

    This is because HttpListener is built on top of http.sys which will listen on the port you specified on behalf of your program.

    It wasn't my EXE doing the actual listening. All I needed to do was to add an Incoming rule to the Windows Firewall set for the "System" program and the specific TCP port I'm using. That allowed remote access.

    0 讨论(0)
  • 2021-01-14 13:05

    Use the HostConfiguration and let Nancy make the URL reservations automaticaly for you.

    var config = new HostConfiguration
    {
        RewriteLocalhost = true,
        UrlReservations = new UrlReservations { CreateAutomatically = true }
    };
    host = new NancyHost(new Uri("http://localhost:8080"), new DefaultNancyBootstrapper(), config);
    host.Start();
    

    Note that this will force ACL to create network rules for new ports if they do not already exist.

    0 讨论(0)
提交回复
热议问题