Press "Enter" to skip to content

Running ASP.NET (https) on a Windows 10 IoT device

In my previous post I needed a couple of pages to explain how to run ASP.NET on a Win10IoT device. How different it is since .net core 2.0 is released! It’s really easy to run a ASP.NET core 2.0 webservice on e.g. the Raspberry Pi, even with HTTPS support. The only downside is that it won’t be an UWP app. To manage the app, you have to use remote powershell instead of the fancy web portal.

I wrote a sample app with a readme which you can find on github, in short:

1. Create an ASP.NET core 2.0 project in VS2017
2. Generate a certificate:

Open a powershell console (must be administrator) and run:

$certData = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname localhost
$pwd = ConvertTo-SecureString -String "p@ssw0rd" -Force -AsPlainText
Export-PfxCertificate -cert "cert:\localMachine\my\$($certData.Thumbprint)" -FilePath c:\temp\testCertificate.pfx -Password $pwd

3. Edit the Program class:

public static IWebHost BuildWebHost(string[] args)
{
    return WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseKestrel(options =>
        {
            options.Listen(
                IPAddress.Any,
                5000,
                listenOptions =>
                {
                    listenOptions.UseHttps("testCertificate.pfx", "p@ssw0rd");
                }
            );
        })
        .Build();
}

4. Publish your service using dotnet

dotnet publish -r win-arm

Copy the publish folder to your device.

5. Run

Create a remote powershell session to your device and execute the .exe

Note: by default, this will only work locally. If you want to access your service from the network, you have to add a firewall exception.

That’s it, happy coding!

  • Andrew Simpson

    so if I used port 80 instead of port 5000 I would not need to open a port up presumably? Is there any reason I would not be able to use port 80?

  • Tom Kuijsten

    Yes, you can just use port 80, no restrictions there. I’m not sure if you have to add a firewall rule for port 80, just test it 🙂