简体   繁体   English

如何使用OWIN自托管提示防火墙例外?

[英]How to prompt for firewall exceptions with OWIN self-hosting?

How is it possible to use a self-hosted server with OWIN and prompt for firewall exceptions? 如何在OWIN中使用自托管服务器并提示防火墙例外? I am running this self-hosted server from a process which cannot guarantee administrator rights, so I can't just add the firewall exceptions programmatically. 我正在从不能保证管理员权限的进程运行此自托管服务器,因此我不能仅以编程方式添加防火墙例外。

I have done some searching and some people have suggested using the TCP listener to 'fake' a port binding to cause a firewall exception prompt to occur: 我进行了一些搜索,有人建议使用TCP侦听器“伪造”端口绑定,以导致发生防火墙异常提示:

IPAddress ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(IPAddress.Any, 32454);

TcpListener t = new TcpListener(ipLocalEndPoint);
t.Start();
t.Stop();

This works and the Windows firewall prompt appears where I can allow my program to be added to the list, however this does not appear to be enough to allow my OWIN server to be accessed externally when I try to hit it from another machine when I start it as follows: 这可以正常工作,并且出现Windows防火墙提示,我可以在其中允许我的程序添加到列表中,但是当我尝试从另一台计算机上启动它时,这似乎不足以允许从外部访问我的OWIN服务器它如下:

var server = Microsoft.Owin.Hosting.WebApp.Start<WebStartup("http://*:32454/);

Note that I'm also using netsh to reserve this url scheme in advance to allow it to work properly from a non-administrator account. 请注意,我还使用netsh预先保留了此url方案,以使其可以从非管理员帐户正常工作。

It almost seems that whatever OWIN is doing is outside the standard executable-based Windows firewall exception. 似乎OWIN所做的一切都超出了基于标准的可执行文件的Windows防火墙例外的范围。 Any ideas on what I'm doing wrong or how to do this properly and let the user add a firewall exception that will work with OWIN? 关于我做错了什么或如何正确执行并让用户添加将与OWIN一起使用的防火墙例外的任何想法?

One solution is to open the port yourself by running 一种解决方案是通过运行自己打开端口

netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80

either using command line or programmatically. 使用命令行或以编程方式。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM