【问题标题】:ASP.NET Core MVC on Windows IoT (Raspbian Pi)Windows IoT (Raspberry Pi) 上的 ASP.NET Core MVC
【发布时间】:2017-12-11 16:41:17
【问题描述】:

我是 Windows IoT 的新手,正在尝试让我的第一个 dot net core 应用程序在 Raspberry Pi 上运行。 这并不是因为我认为 Raspbian Pi 是托管网站的理想场所,而是我的目标是在 Pi 上实现一个测量和控制系统,并通过 REST API 使整个东西都可以访问。 首先,我想从 VS2017 模板创建一个标准的 dot net core 应用程序并让它在 Pi 上运行。

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

从之前的实验中我知道,该应用只在本地主机上监听,所以我修改了 Program 类如下:

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();
    }
}

现在服务器也可以通过我的手机使用 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

树莓派(经过深思熟虑后)回答与在 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。

我错过了什么?

【问题讨论】:

  • 你的windows iot core是什么版本的?你使用的 DotNetCore 版本是什么?
  • AspNetCore 是 2.0.3,不确定 IoT 版本(我会在返回时检查)但它是上周新下载的。

标签: asp.net-mvc raspberry-pi3 windows-iot-core-10


【解决方案1】:

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

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

【讨论】:

  • 我猜你建议在 Raspberry 上宣传这条规则?如果是防火墙问题,它不会被“主动拒绝”而不是超时吗?
  • 是的,原因是防火墙拒绝了web请求,所以需要在树莓派上添加规则。Time Out的信息表示该客户端无法获得响应,但在客户端,它不知道服务器是拒绝请求还是关闭。
  • 太棒了——确实是防火墙。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多