简体   繁体   English

如何远程访问自托管的Nancy服务?

[英]How do I remotely access self-hosted Nancy service?

I am creating a simple Windows service that hosts a Nancy instance to provide views of its internal data. 我正在创建一个简单的Windows服务,该服务承载Nancy实例以提供其内部数据的视图。 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;" IE最终将显示“无法显示此页面;” Safari on an iPad shows the partial progress bar for a while and does nothing. iPad上的Safari会在一段时间内显示部分进度条,并且什么也不做。

I'm binding using all local IPs, not just localhost. 我使用所有本地IP绑定,而不仅仅是本地主机。 I am using the GetUriParams() function at this link to discover all local IP addresses for binding. 我在此链接上使用GetUriParams()函数来发现所有本地IP地址以进行绑定。 http://www.codeproject.com/Articles/694907/Embed-a-web-server-in-a-windows-service 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. 我在此页面上发现绑定到localhost仅适用于本地访问。 http://forums.asp.net/t/1881253.aspx?More+SelfHost+Documentation 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. 此功能发现的IP用于以太网适配器,无线适配器和先前安装VMware Player的两个VMware Network适配器。 I've tried the remote access both by machine name and by literal IP to the Ethernet adapter. 我已经尝试通过计算机名称和按原义IP远程访问以太网适配器。

I added entries to urlacl list. 我在urlacl列表中添加了条目。 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 我在许多地方都使用了netsh http add urlacl命令,包括在以下链接中所建议的: 远程访问Nancy Self Host

If I perform netsh http show urlacl , I see the entry for the port I'm using. 如果执行netsh http show urlaclnetsh http show urlacl看到我正在使用的端口的条目。

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. 我尝试了不同的Nancy配置,如果我为UrlReservations.CreateAutomatically设置了Nancy配置选项,则会收到安全提示,允许后,我会在netsh http show urlacl看到新条目, netsh http show urlacl所有本地IP的netsh http show urlacl列表输出,但仍然没有允许远程访问。 I also tried the RewriteLocalHost option true and false. 我还尝试了RewriteLocalHost选项true和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() ). 我尝试使用http://+:3684http://*:3684 (从Uri()获取解析异常)和http://0.0.0.0:3684 (从AddAllPrefixes()获取异常) AddAllPrefixes()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 我将EXE添加到Windows防火墙中,并按如下所述创建了防火墙例外: https : //msdn.microsoft.com/zh-cn/library/ms733768.aspx

The associated rule shows Private,Public and "Any" for every column with both TCP and UDP. 关联的规则针对具有TCP和UDP的每一列显示“专用”,“公共”和“任何”。

I tried running Nancy in different environments. 我尝试在不同的环境中运行Nancy。 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. 我已在以下代码中运行代码:作为本地系统运行的Windows服务,Visual Studio 2013调试器中的控制台应用程序以及控制台应用程序以管理员身份运行。

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? 我想念什么?

This answer provided the clue I needed. 这个答案提供了我需要的线索。 https://stackoverflow.com/a/21364604/1139376 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. 这是因为HttpListener构建在http.sys之上,它将在您代表程序指定的端口上进行侦听。

It wasn't my EXE doing the actual listening. 不是我的EXE在做实际的监听。 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. 我需要做的就是向Windows防火墙设置“系统”程序和我正在使用的特定TCP端口添加传入规则。 That allowed remote access. 允许远程访问。

Use the HostConfiguration and let Nancy make the URL reservations automaticaly for you. 使用HostConfiguration并让Nancy为您自动进行URL保留。

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. 请注意,这将强制ACL为新端口创建网络规则(如果尚不存在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 南希自托管RunTimeBinderException - Nancy Self-Hosted RunTimeBinderException 无法在本地网络中远程访问WCF自托管服务 - WCF self-hosted service is not accessible remotely in local network 如何将用户名/密码凭据从php客户端传递到自托管的wcf服务? - How do I pass username/password credentials from php client to self-hosted wcf service? 自托管WCF服务:如何从托管应用程序访问实现服务合同的对象? - Self-hosted WCF service: How to access the object(s) implementing the service contract from the hosting application? WCF REST服务(自托管)只能在本地网络中访问(必须远程访问) - WCF REST Service (self-hosted) accessible only in local network (and must be accessed remotely) 我可以在本地调用自托管WCF服务中的方法吗? - Can I call a method in a Self-Hosted WCF Service locally? 如何使我的自托管WCF服务不尝试保留localhost以外的URL? - How can I make my self-hosted WCF service NOT try to reserve urls other than localhost? 如何设置WCF自托管REST服务? - How to set up WCF Self-Hosted REST service? 如何在没有代理的情况下调用自托管TCP服务? - How to call self-hosted TCP service without proxy? 为什么/如何将自托管WCF服务迁移到IIS7? - Why/how to migrate self-hosted WCF service to IIS7?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM