预期结果
我正在尝试使用Kestrel制作一个ASP.NET Core5.0应用程序,我想将服务器端口自动移植。
套餐
我目前正在使用OpenNat.Core包。我也尝试过常规的OpenNat,也出现了同样的问题。
问题
当端口转发时,程序说它已经正确地映射了所有的东西,而地图甚至在列出我的路由器上所有映射的端口时显示。然而,当我试图通过CanYouSeeMe.org查看它的状态时,它会返回一个超时错误,并且无法访问网络之外的服务器。
我试过的
代码
using Open.Nat;
using System;
using System.Threading;
using System.Threading.Tasks;
...
public static async Task OpenPort(int port, string description)
{
try
{
NatDiscoverer discoverer = new NatDiscoverer();
CancellationTokenSource cts = new CancellationTokenSource(10000);
NatDevice device = await discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts);
Mapping map = new(Protocol.Tcp, port, port, description);
await device.CreatePortMapAsync(map);
Console.WriteLine($"Created {map}");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}发布于 2021-08-20 04:15:10
不用担心我的防火墙挡住了应用程序。我能够动态地添加防火墙规则来解决这个问题。
https://stackoverflow.com/questions/68843127
复制相似问题