How do I remotely access self-hosted Nancy service?

拥有回忆 提交于 2019-12-01 11:53:19
cdburgerjr

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!