Reputation: 1499
I am new to Windows IoT and am trying to get my first dot net core app running on a Raspberry Pi. It is not because I think the Raspbian Pi is the perfect place to host web sites, but my ambition is to implement a measurement and control system on the Pi, and make the whole thing accessible through a REST API. First things first, I wanted to create a standard dot net core app from the VS2017 template and get it running on the Pi.
The template built an App that was available on http://localhost:62100.
As I knew from previous experiments, the app was only listening on localhost, so I modified the Program class as follows:
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();
}
}
And now the server was also usable from my phone using the PC’s IP address.
In order to prepare the project for the Pi, I opened a PowerShell in the folder, where the project file resides (in my case C:\Users\\Documents\Visual Studio 2017\Projects\AspNetCore\AspNetCore) and ran the command:
dotnet publish -r win10arm
And then I copied all of the files placed under bin\Debug\netcoreapp2.0\win10-arm\publish to the Pi and start the application from the PowerShell connected to the Pi:
.\AspNetCore.exe
The Pi (after some deep thought) answers as when it was run on the 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.
But trying to access the server from my browser (http://192.168.200.106:62100) times out with ERR_CONNECTION_TIMED_OUT.
What am I missing?
Upvotes: 0
Views: 625
Reputation: 4432
You need to add the port to firewall with following cmdlet in powershell,by default ASP.Net Core binds to http://localhost:5000.
netsh advfirewall firewall add rule name="ASPNet Core 2 Server Port" dir=in action=allow protocol=TCP localport=62100
Upvotes: 1