ASP.NET Windows 物联网 (Raspbian Pi) 上的核心 MVC

ASP.NET Core MVC on Windows IoT (Raspbian Pi)

我是 Windows 物联网的新手,正在尝试在 Raspberry Pi 上安装我的第一个点网核心应用 运行。 这并不是因为我认为 Raspbian Pi 是托管网站的完美场所,而是我的目标是在 Pi 上实现一个测量和控制系统,并通过 REST API. 首先,我想从 VS2017 模板创建一个标准的 dot net 核心应用程序,并在 Pi 上 运行ning。

该模板构建了一个可在 http://localhost:62100 上使用的应用程序。

正如我从之前的实验中了解到的,该应用程序仅在本地主机上监听,因此我修改了程序 class 如下:

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args)
    {
        var configuration = new ConfigurationBuilder()
            .AddCommandLine(args)
            .Build();
        var hostUrl = configuration["hosturl"];
        if (string.IsNullOrEmpty(hostUrl))
            hostUrl = "http://0.0.0.0:62100";

        return new WebHostBuilder()
            .UseKestrel()
            .UseUrls(hostUrl)
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .UseConfiguration(configuration)
            .Build();
    }
}

现在我的服务器也可以使用 phone 使用 PC 的 IP 地址。

为了为 Pi 准备项目,我在项目文件所在的文件夹中打开了一个 PowerShell(在我的例子中是 C:\Users\\Documents\Visual Studio 2017\Projects\AspNetCore\AspNetCore)和运行 命令:

dotnet publish -r win10arm

然后我将 bin\Debug\netcoreapp2.0\win10-arm\publish 下的所有文件复制到 Pi 并从连接到 Pi 的 PowerShell 启动应用程序:

  .\AspNetCore.exe

Pi(经过深思熟虑后)在 PC 上 运行 时的回答:

  [192.168.200.106]: PS C:\CoreApplications\AspNetCore> .\AspNetCore.exe
  Hosting environment: Production
  Content root path: C:\CoreApplications\AspNetCore
  Now listening on: http://0.0.0.0:62100
  Application started. Press Ctrl+C to shut down.

但是尝试从我的浏览器 (http://192.168.200.106:62100) 访问服务器超时 ERR_CONNECTION_TIMED_OUT。

我错过了什么?

您需要在 powershell 中使用以下 cmdlet 将端口添加到防火墙,默认情况下 ASP.Net 核心绑定到 http://localhost:5000.

netsh advfirewall firewall add rule name="ASPNet Core 2 Server Port" dir=in action=allow protocol=TCP localport=62100