How do I remotely access self-hosted Nancy service?

一世执手 提交于 2019-12-01 08:02:09

问题


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 machine; I see the view that it serves up. However, I cannot find any reason why it will not access from a remote browser (on the same network). Access from a remote browser simply delays a while; IE will eventually display "This page can’t be displayed;" Safari on an iPad shows the partial progress bar for a while and does nothing.

I'm binding using all local IPs, not just localhost. I am using the GetUriParams() function at this link to discover all local IP addresses for binding. http://www.codeproject.com/Articles/694907/Embed-a-web-server-in-a-windows-service

_nancyHost = new NancyHost(GetUriParams(port));
_nancyHost.Start();

I discovered at this page that binding to localhost works for local access only. http://forums.asp.net/t/1881253.aspx?More+SelfHost+Documentation

The IPs that this function discovers are for Ethernet adapter, Wireless adapter, and two VMware Network adapters from a prior installation of a VMware player. I've tried the remote access both by machine name and by literal IP to the Ethernet adapter.

I added entries to urlacl list. I have used the netsh http add urlacl command as recommended in many places, including at this link: Remote access to a Nancy Self Host

If I perform netsh http show urlacl, I see the entry for the port I'm using.

I tried different Nancy configs If I set the Nancy configuration option for UrlReservations.CreateAutomatically, I will get security prompts, which after allowing, I see new entries in netsh http show urlacl list output for all of the local IPs, but it still does not allow remote access. I also tried the RewriteLocalHost option true and false.

I've tried starting Nancy with http://+:3684 or http://*:3684 (which gets parsing exception from Uri()) and with http://0.0.0.0:3684 (which gets exception from AddAllPrefixes() within HttpListener()).

I added the EXE to Windows firewall I have created firewall exceptions as described here: https://msdn.microsoft.com/en-us/library/ms733768.aspx

The associated rule shows Private,Public and "Any" for every column with both TCP and UDP.

I tried running Nancy in different environments. I've run the code in: the Windows Service running as Local System, a console app within Visual Studio 2013 debugger, and the console app Run As Administrator.

I imagine it's a simple security setting, but I've googled and searched and tried various things for a couple of days now.

What am I missing?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/33559157/how-do-i-remotely-access-self-hosted-nancy-service

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