Running ASP .NET vNext on a pcDuino

Microsoft is doing a lot of great things at the moment.  One of these is the ability to run ASP .NET vNext away from a Windows Server, and away from IIS.    Being a ASP .NET Mvc developer for a few years now, the idea to run on any environment is quite liberating.

 

A pcDuino is a device with tons of potential.   It’s a powerful device and it really is a full “mini PC” with enough processing power to do interesting things like image processing.    But is small enough to be used in situations where you would uses an Arduino, Netduino, RFduino etc in the IoT or maker space.   The pcDuino also has an Ethernet port and on-board WiFi, so it is a rather compelling internet connected device.

Having deployed Mono on my board already, it was also a no brainer to extend that and to explore the potential of an internet connected device but leveraging ASP .NET vNext to do that.

 

asp net web server

ASP .NET Web Server (with Arduino Uno and Xamarin Monkey used for scale)

 

 

To get started read these two blog posts:

 

Now that we have both Ubuntu and Mono installed, we can now begin getting ASP .NET vNext up and running.

To figure out how to do this, I referred to the ASP .NET github repository, “Getting Started” page.  This page can be found here:  https://github.com/aspnet/Home

 

Lets start by installing the necessary certificates.

$ CERTMGR=/usr/local/bin/certmgr
$ sudo $CERTMGR -ssl -m https://go.microsoft.com
$ sudo $CERTMGR -ssl -m https://nugetgallery.blob.core.windows.net
$ sudo $CERTMGR -ssl -m https://nuget.org
$ sudo $CERTMGR -ssl -m https://www.myget.org/F/aspnetvnext/
$ mozroots --import --sync

 

We need curl, so install that next

$ sudo apt-get install curl

 

Download and execute the KVM installer on the ASP .NET site.   As of writing this,  the master branch has the 1.0.0-beta1, so we will use that.

$ curl https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh && source ~/.kre/kvm/kvm.sh
$ kvm upgrade

 

Check to see if the installation is correct, you should see the version number reflected with the list command.

$ kvm list

 

If git is not already installed, install git next.

$ sudo apt-get-install git

 

The web server ASP .NET vNext uses (Kestrel), is based on Libuv, so we need to install that next.

$ git clone https://github.com/libuv/libuv.git
$ cd libuv
$ sh autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install

 

Now we need something to run.  Lets use one of the samples from the ASP .NET github repository.for simplicity.  Clone the aspnet repository.

$ git clone https://github.com/aspnet/Home

 

Focusing on the Mvc example, change to the directory “HelloMvc”.    To resolve and download the necessary dependencies for the project, execute a restore command on the package manager “KPM”.

$ cd Home/samples/HelloMvc
$ kpm restore

 

We need to set up a symbolic link for libuv to avoid any “Object Reference not set to an instance of an object” errors.    This is not the most helpful or informative of error messages, but we get what it means.

 $ ln /usr/local/lib/libuv.so -sf ~/.kpm/packages/Microsoft.AspNet.Server.Kestrel/1.0.0-beta1/native/darwin/universal/libuv.dylib

 

Run the Kestrel server

$ LD_LIBRARY_PATH=/usr/local/lib k kestrel

 

If all goes well you should see “Started” appear on the command line.

$ Started

 

The default port for kestrel is 5004.   As a test navigate to “http://localhost:5004” using the internal pcDuino Chromium browser.     The sample ASP .NET Mvc application should appear as below.

 asp .net vnextAsp .NET Mvc site up and running on Mono 3.12.0

 

Find the ip address of the pcDuino using the ifconfig command.

$ ifconfig

 

Use this ip address from a remote device (or pc’s) browser.   The great feature of the pcDuino that it is equipped with both an Ethernet port and WiFi so connectivity is very easy and convenient.

 

Congratulations you now have a Mono / NET powered IOT device running ASP .Net vNext!   A mobile wireless web server / web connected device has endless potential.   In future blog posts I hope to explore some of those.

 

I hope this was helpful!

apead

I am a Xamarin Most Valueable Professional (MVP), Microsoft Developer Technologies MVP, Microsoft Internet of Things MVP, Microsoft Azure MVP, Architect, Software Developer, Organizer and Sponsor of the CPTMSDUG, JHBMSDUG and DBNMSDUG User Groups and father of 2.