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

Rethinking the way we build on the cloud: Layering the Cloud

To help, you can split your cloud architecture into three layers: Visible Volatile Persistant Visible This is the layer between the cloud and the rest of the world. It is mainly public DNS entries, load balancers, VPN connections etc. etc. These things are fairly static and consistent. If you have a website you will want the same A Name records pointing at your static IP. Things in the visible layer rarely change or if they do they are for very deliberate reasons. Volatile This is where the majority of your servers are. It’s called volatile because it tends to change a lot. The known state (how many servers, what versions of which software they run etc.) are changing frequently, perhaps even several times per hour. Even in a traditional data centre your servers are being upgraded, having security patches applied, new versions of software deployed, extra servers added etc. On the cloud this is even more volatile when you use patterns such as the Phoenix server and m...

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...

DANGER (STILL) LURKS IN THE INTERNET OF THINGS (IOT)

All of the media, both “mainstream” and “tech”, has gushed over all of the new appliances and devices that are now in the category of what we would call the Internet of Things.  Items like home security,  home lighting, and refrigerators, to name a few. There are many advantages to having connected appliances and devices, Threats that can and will be exploited if unsuspecting users don’t secure them.   Two “layers” of security : The first layer of offering  is a security API that will provide [a way] to easily do a virtual patch, to prevent a remote attack, for example . . . the third layer is cloud: IoT cannot do anything without the cloud.  Most data is sent to the cloud and you will need to have proper protection and make sure the cloud is always available. In both situation Users are vulnerable, mostly due to their own apathy.  Users often either don’t know how to patch their own machines (and in this case, devices) or have glanced...