Skip to main content

Running ASP.NET Core 2 Apps on Windows 10 IoT Core

Want to get your ASP.NET Core apps working on Windows 10 IoT Core? Here's what you need to know using ASP.NET Core 2 and some minor hacking.

It has been problematic to run ASP.NET Core applications on Windows 10 IoT Core, as it is not an officially supported scenario yet, and many components we are used to are not built with Windows 10 ARM in mind. Still, it easy to run web applications on Windows 10 IoT Core using ASP.NET Core 2. There are few tricks developers should know when building web applications for Windows 10 IoT Core.
A few things to mention before getting our hands dirty with the real stuff:
  • ASP.NET Core on Windows 10 IoT Core is not officially supported yet.
  • There is only .NET Core runtime available for Windows 10 on ARM, but no SDK (yes, there is no dotnet restore and dotnet build, etc., available).
  • Not all things that work on your dev box will work on Windows 10 IoT Core, and some of these things come out when trying to run a web application on a board.
With these warnings in mind, let’s start in safe waters and make a default ASP.NET Core 2 web application run on Windows 10 IoT Core.

Building the Web App

I created a default ASP.NET Core 2 web application with Visual Studio and made the compiler build an EXE file that can be run directly. Just open the project file and add this output type setting:
<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <OutputType>Exe</OutputType>
</PropertyGroup>

Now we can build a web application just to find out that the EXE file is not there. We will get it when publishing the application.
Before building and deploying our web application to our board, we have to make it listen port 5000 on all interfaces. For this, we modify the program class and use * as the host name.
public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }       public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseUrls("http://*:5000")
            .UseStartup<Startup>()
            .Build();
}

To deploy our application to Windows 10 IoT Core, we need to publish it and tell the dotnet utility that we want to support Windows 10 on ARM. This is done using the following command.
dotnet publish -r win-arm

If everything went well, then the published files are in the folder bin\Debug\netcoreapp2.0\win-arm\publish.
.
ASP.NET Core 2 application published for Windows 10 IoT CoreThe size of the publish folder, in my case, is 73 MB.

Deploying the Web App to Windows 10 IoT Core

To make a simple test run for our web application, we need to deploy it to Windows 10 IoT Core. Here are steps to follow.
  1. Open PowerShell with Administration permissions and run the following command: 
    Enter-PSSession -ComputerName minwinpc -Credential minwinpc\Administrator

    When the login dialog opens, enter your Windows 10 IoT Core password.
  2. Create a folder for the web application and move to this folder: 
    mkdir webapptest
    cd webapptest
     
  3. Open Windows Explorer and move to your board’s drive: 
    \\minwinpc\c$ 

    Enter the password when asked, and then move to webapptest folder.
  4. Take files from the web application publish folder and copy these to the webapptest folder created before.
  5. Run the following command in PowerShell to open port 5000 of board: 
    netsh advfirewall firewall add rule name=”ASP.NET Core Web Server port” 
    dir=in action=allow protocol=TCP localport=5000
     
  6. Next, in PowerShell, run the web application using the EXE file: .\WebApplication6.exe 
If there are no problematic dependencies in our web application, then we can see some output to the PowerShell window.
ASP.NET Core 2 application running on Windows 10 IoT Core
Notice that ASP.NET Core is listening to port 5000 on all network interfaces. Let’s open the application now using a browser.
ASP.NET Core 2 application running on Windows 10 IoT Core
We don’t see any debug output in PowerShell except exceptions (if there are any).
Note: The frst request to the web application is very slow, but after that, the app works fast and doesn’t put much load on the board. Most of the requests don't consume much CPU, and the working set of memory is around 104 MB.

Wrapping Up

Previously, it was harder to make ASP.NET Core applications run on Windows 10 IoT Core, but with ASP.NET Core 2, we can do it with less effort and hacking. All we had to do to make a default web application run on Windows 10 IoT Core was build it as an executable and then publish it to the board.
It is still risky business, as many things that run on usual boxes without any issues are not built with Windows on ARM in mind, and issues with these components usually appear when running the application on board. Still, we can use ASP.NET Core on Windows 10 IoT Core and come out with solutions where a simple web server on a board is needed.

Comments

Popular posts from this blog

Common Sense Identification of the Security Problems

Organizations make key information security mistakes, which leads to inefficient and ineffective control environment. High profile data breaches and cyber-attacks drive the industry to look for more comprehensive protection measures since many organizations feel that their capability to withstand persistent targeted attacks is minimal. But at the same time, these organizations make some key information security mistakes, that jeopardize their efforts towards control robustness. Although many firms invest in security technologies and people, no one has the confidence that the measures taken are good enough to protect their data from compromises. Below are the 10 worst mistakes which are common to find, and important to address in the path of mature information security posture. If you analyze the cyber security scenarios, and organizational capabilities, the prevailing trend is a vendor-driven approach. In many cases, security professionals adopt the attitude of procuring...

Real-Time Talk: Windows 10 IoT Core Background Tasks and ASP.NET Core Web Apps

Display useful information from your Windows 10 IoT Core application in an ASP.NET Core web app, essential for integrating IoT data into a solution. Windows 10 IoT background task talk with a web application using WebSockets. Problems As my path to this solution has been troublesome, I am listing here the main problems I faced so my dear readers have a better idea of dead-end streets along the way: I was not able to make the ASP.NET Core web application run under a Windows 10 IoT background service. I found no information about when or if it will be supported in the near future. ASP.NET MVC and ASP.NET Core have different SignalR implementations. I was not able to make a SignalR client for .NET Core work with SignalR hosted on a web application. I was able to make things work by directly using a WebSocket. It’s not as nice a solution as I had in my mind, but it works until things get better. Making the Background Task and Web Application Talk I worked out sim...

Python and Parquet Performance

In Pandas, PyArrow, fastparquet, AWS Data Wrangler, PySpark and Dask. This post outlines how to use all common Python libraries to read and write Parquet format while taking advantage of  columnar storage ,  columnar compression  and  data partitioning . Used together, these three optimizations can dramatically accelerate I/O for your Python applications compared to CSV, JSON, HDF or other row-based formats. Parquet makes applications possible that are simply impossible using a text format like JSON or CSV. Introduction I have recently gotten more familiar with how to work with  Parquet  datasets across the six major tools used to read and write from Parquet in the Python ecosystem:  Pandas ,  PyArrow ,  fastparquet ,  AWS Data Wrangler ,  PySpark  and  Dask . My work of late in algorithmic trading involves switching between these tools a lot and as I said I often mix up the APIs. I use Pandas and PyArrow for in-RAM comput...