Remote access to a Nancy Self Host

余生长醉 提交于 2019-12-17 18:28:40

问题


I am creating a Nancy Module that will eventually be hosted inside of a Windows Service. I am currently running it inside of a WPF test application. To start the Nancy hosting, I am using Nancy.Hosting.Self and calling:

nancyHost = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:8080"));
nancyHost.Start();

On my local machine I am able to go to a web browser and access my module by entering http://localhost:8080 into the address bar.

If I go to another machine I am not able to access the service. My Windows Firewall is turned off.

If I start the hosting with anything other than localhost in the baseUri, I get an "access denied" exception upon calling nancyHost.Start();

Is there something that I am missing? Should I be able to access the Nancy module from any machine as long as I know the IP:Port to the machine doing the hosting? Is there any type of "host headering" that I need to be aware of?

Thanks for your help with this.


回答1:


Windows will prevent you from listening on ports without permission. You can either run your process as administrator, or add permission using "netsh":

netsh http add urlacl url=http://+:8080/app user=domain\user

The "+" is a wildcard so it can listen on any IP.

Normally you'd handle the latter during installation, so you may want to run as admin to debug, then make sure your installer sets the relevant permissions.




回答2:


For local debugging, use

http://+:8733/Design_Time_Addresses

You can add any subdirectory you like, for example

http://+:8733/Design_Time_Addresses/myService 

and debug it at

http://localhost:8733/Design_Time_Addresses/myService

without running your IDE (Visual Studio?) as Administrator.




回答3:


Look this: Self-Hosting-Nancy

The Host Configuration: UrlReservations, add under code:

var configuration = new HostConfiguration
        {
            UrlReservations = new UrlReservations { CreateAutomatically = true }
        };

OK, you can create your host!~



来源:https://stackoverflow.com/questions/8548678/remote-access-to-a-nancy-self-host

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