Internal Server Error after Upgrading to .NET Core 1.1

So I decided to start upgrading all my Azure Web Apps and associated NuGet packages to to .NET Core 1.1. The process was very simple and everything worked perfectly locally.

Naturally, I pushed my update to my GitHub repo, Azure takes over and does the deployment. Then.. FAIL

An Error occurred while starting the application.

First thing I try is to re-sync the repo through the admin. No luck. Thankfully though, there is a simple solution.

Turns on when doing the deploy there are left over dll’s in your wwwroot folder that will conflict with your new dll’s. This causes the web app to fail.

To resolve this error, simply do the following.

Stop your web app

Go to your Kudu console either through advanced tools or directly from the scm url.

Go to the CMD or Powershell prompt. Navigate to the /site/wwwroot folder. Delete everything in it!

Go back to deployment options and re-sync your Github Repo

Once this is done start your application and you will be good to go!

Azure Functions with Multiple Output Bindings

Recently while working on a partner project, it was required that we build an Azure Function that not only outputs to an Azure Storage Queue, but also archives that same message in Azure Storage. While the concept itself is simple, I wanted to use the built in Azure Functions bindings to do this as simply and cleanly as possible. After a little research, it turns out this is possible and very easy to implement.

The following walks you through how to create an Azure Function with a manual trigger that both sends a message to Azure Table Storage and Azure Queue Storage through built in Azure Function Bindings.

As with anything, there are multiple ways you can do this. I will walk you through from the very beginning starting with the easiest method, through the Azure Portal.

The following assumes you have an Azure Account. If not you can sign up for a free trial here or you can try the Azure Functions for free by clicking here.

If you would like to skip the tutorial and go right to the code, you can view the repo here: Azure Functions Multiple Output Bindings.

Create a new Function App (you can skip this step if you are using the try Azure Functions demo)

This will create your Azure Function App Service and a corresponding blob storage account. For the demo we will use this blob storage account but technically you could use any by utilizing the connection string.

 

 

Browse to the new function app you created. Click on new function, choose C#, then ManualTrigger-CSharp and click create.

Note; We are doing a manual trigger for demo purposes but you could use any of the triggers available.

Great! Now we have an Azure Function created. Lets add some output bindings. Click on “Integrate

From here, we can easily add multiple output bindings through the interface.

Click on New Output, choose Azure Queue Storage and click Select

Leave all the default values and click Save. We will come back to these later.

Again, click on New Output, this time choose Azure Table Storage, and hit Select.

Again, let’s leave all the default values and click Save.

Behind the scenes, the portal interface has been modifying your function.json file which contains all the trigger and binding information for your Azure Function. Your function.json should now look like this.

You can get to this by click on “view files” and selecting function.json.

function.json tells the Azure Function that you now have two output binding and holds their configuration values. In this case we want to output to a table named outputTable and a storage queue names outqueue. All this using the default connection to the storage account we created.

Note; you do not have to create the Azure Storage Queue or Table. It will automatically be created if it does not exist.

All we need to do now is add some code to the function to send data to those bindings.

Let’s go back to our run.csx and replace all the code with the following:

Click save and if you did everything correctly you should see Compilation Succeeded

That’s it! You now have an Azure Function that can easily write to Azure Table Storage and Azure Storage Queue using built in Output bindings and very little code.

If you go ahead and run it you should get the following message. In addition, if you open the storage account for the function you will see the new table and queue created with the messages stored.

Deploy Azure Web App or Azure Function from Repository Folder

I participate in a lot of hackathons. Whether its an internal up-skilling event, university hackathon, or on site with a partner. These are often some of the most fun and frustrating things I get to work on.

At just about every hackathon, we use GitHub to setup a central repo with all the parts of the project we are working on. This could for example contain a web app, azure functions, Xamarin app, console app etc. We normally will just throw everything into its own folder and work from the one repo to keep it easy for everyone.

Often, I want to deploy my web app (and only the web app) right from this repo as I am pushing changes to GitHub. Thankfully through Azure, not only is it very easy to setup continuous deployment using GitHub, but you can also specific what folder within the repo to deploy from.

To deploy an ASP.NET Core web app to Azure from a specific folder in your repository, you simply have to add a new application setting called ‘project’ and point it to the source folder of the project.

For example; I have a project consisting of a UWP slideshow application and my web app to manage the slides. The repository can be found here: https://github.com/joescars/MICMediaSlideshow

In this instance, I only want to deploy the folder ‘MicMediaManager’ to my web app. To do this I connected my Azure Web App to GitHub for continuous deployment and then added the following settings to my app settings.

That’s it! Now I can update each folder independently and my web app will only publish changes within the source folder specified.

So… what about Azure Functions?

This same method works with Azure Functions as well. I’ve setup a sample repository here: https://github.com/joescars/AzureFunctionsCustomDeployment in which I have a folder with my Functions inside their own sub-folder. I then go to the function app settings, add a project setting and it will deploy all my Functions from that folder.

Happy Coding!

Azure IoT Hub, Azure Functions and Farming!

Late last year I had the opportunity to work with Costa Farms on a small proof of concept project. The goal was simple; actively monitor pH levels in their plants water supply and take intelligent action if needed.

We were able to accomplish this using Azure IoT Hub, Stream Analytics, Event Hubs and Azure Functions.

You can find the full case study here.

In addition please find a slide deck below with additional info.

Using Google Authentication with ASP.NET Core (ASP.NET 5)

** UPDATE – PLEASE READ **

Please visit: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins for updated instructions on how to use Google Authentication with ASP.NET Core.

The instructions in this article are out of date and I have not yet had a chance to update it.


While speaking with some local developers about ASP.NET Core I was asked if integrating Google Authentication was just as easy in ASP.NET Core, Core MVC (MVC6) as it was in the past. I honestly had not tested it yet so I decided to give it a shot. Thankfully, its very simple, but slightly different, so I’ve included detailed instructions below.

Note; this assumes you have Visual Studio 2015 Update 1 and ASP.NET 5 RC1 Installed. If not you can get both from the following links:

Create a new ASP.NET 5 MVC Project

Go to File -> New Project

1-vs-2015-new-project

Select ASP.net Web Application. Name your App and hit Ok

2-Web-Application-Name

Select Web Application under “ASP.NET 5” Templates

3-select-asp-net-5-web-application

Let Visual studio create the project and automatically restore the packages.

Once the solution loads, hit CTRL+F5 to run your app. Note the URL it runs on and copy this URL as we will use it later.

4-run-project-to-get-url

Setup and Create a new Google OAuth 2.0 Client ID and Secret

Head over to https://console.developers.google.com and sign in with your Google account

05-google-developer-console-home

In the top right click on the “Select a project” drop down and choose “Create a project”

06-google-developer-console-create-project

In the new project dialog that pops up enter a name for your project, agree to the terms and click “create”

07-google-developer-console-name-app

You will now be returned to your dashboard. Click on Enable and Manage API’s

08-enable-manage-apis

In the window that pops up choose the project you just created and hit continue

09-google-select-project

On the next page scroll down and click on Google+ API

10-select-google-plus-api

On the next screens click Enable and then Go to Credentials

11-select-enable

12-goto-credentials

On the Add Credentials screen choose Google+ API and Web server from drop downs. Choose User data under “What data will you be accessing” and click “What credentials do I need”

13-add-credentials

Remember how I had you save the url of your project? There is where we enter it. In the first box enter in the URL and make sure to remove the trailing / . In the second box add the same url but end it with /signin-google . Once you have done this click on Create client ID

14-add-credentials-filled-out

The next screen will let you customize the Google Consent page. This is the page the users see where they have to allow you to access their data. Just enter in a product name for now and click Continue

15-consent-screen

You are now done! Google only shows you the Client ID right away so I will show you how to go back and display your Client ID and Client Secret. First click Done on this screen

16-done-shows-clientid

The next screen shows all the credentials you have setup. Simply click on the first credential name.

17-apps-listed

This screen now shows your Client ID and Client Secret. Make note of both of these because we are going to use them in your project.

18-google-dev-console-shows-clientid-clientsecret

Setup your ASP.NET Core Application with Google Authentication

Now that we have the project setup and your Google Client ID and Secret, we simply need to modify the project to use Google Authentication.

First we need to install the Google Authentication Nuget package. To do this, let’s switch back over to Visual Studio and open up your project.json file. In the dependencies section add the following piece of code to the end.

It should look like this

19-add-google-authentication-package-project-json

Notice that when you do this, Visual Studio will automatically download and install the Nuget package setting up all your reference for you.

20-nuget-auto-restores-package

Now lets open up Startup.cs add add the following code. NOTE: It is important you add this code after app.UseIdentity(); and before app.UseMVC()

It should look like the following. Of course replace the values with your Client ID and Client Secret

21-edit-startup-add-google-auth

Let’s now run the project, CTRL + F5, and click login in the upper right hand corner. You should now see a page similar to the one below.

23-google-auth-consent-screen

Once the user hit’s allow they can authenticate using Google.

Technically we have done everything to get Google Authentication working. But, being I started from a brand new project I am going to continue and show you how to update the database use a migration so that the project will run properly.

Applying a database migration using DNX

If you followed this tutorial from the very beginning and started with a new project, you will get an error after hitting “Allow” similar to the one below.

24-ef-error

How to we fix this? Easy, open up a command prompt in the project folder. Run the command “dnx ef database update”. This will apply the initial database migration.

26-dnx-ef-update

Once you have done that, refresh your page and you are good to go! It should ask you to finish setting up your account and then log you into the site.

27-authentication-success

28-success-google-auth-works-asp-core

I hope you found this tutorial helpful! Happy Coding!

Getting started with ASP.NET Core 1.0

This was presented at South Florida Code Camp 2016.

You can find the code from the demo here: https://github.com/joescars/SFCCASPCoreDemo

In this presentation I walk you through how to get started with ASP.NET Core 1.0. We focus on the cloud and cross platform story.

I walk you through the following:

  • High level overview of ASP.NET Core
  • How to install ASP.NET Core
  • Creating an ASP.NET Core project in Visual Studio
  • Project structure and overview
  • Local debugging and building
  • Pushing the website to Azure using local Git repository

We then switch over to the MAC and continue with the following

  • How to install and configure ASP.NET core and Visual Studio Code on the MAC
  • Pulling the project down to MAC via Git
  • Editing the project in Visual Studio Code
  • Building the project and running locally using Kestrel Web server
  • Pushing the updates back up to Azure using Git

How to Deploy Vorlon.JS to Azure Web App

This video will walk you through how to deploy Vorlon.JS to an Azure Web App using Git version control. The pre-requisites for this video are that you have an active Microsoft Azure account and node.js installed.

Instructions

  1. Create new web app using custom create
    1. From the configure section, Turn on Web Sockets – Save
  2. Go Back to Dashboard
  3. Setup deployment from source control
    1. Select Local Git Repository
      1. This will create the Git repository
  4. Install VorlonJS on your machine
  5. nodejs must be installed already. If not, install from nodejs.org
    1. Open node.js command prompt
    2. Enter the following: npm i –g vorlon
  6. Test Vorlon
    1. Type the following: vorlon
      1. To terminate: Terminate – ctrl + c
  7. You should be in your user folder. We must now browse to the proper folder
    1. cd appdata
    2. cd roaming
    3. cd npm
    4. cd node_modules
    5. cd vorlon
  8. Type: start . (this will launch explorer)
  9. Open another explorer
    1. Create a new folder (ex C:\Dev\VorlonJS)
  10. Copy node_modules folder from vorlon folder to the new folder
  11. Copy all the files WITHIN the server folder (within vorlon folder) to the new folder you created
  12. Create new text file package.json
  13. Edit the file and add the following

Now we want to commit this into azure website

  1. Open Git Bash
    1. Get GIT url from Azure Deployments page
      1. It also has instructions
    2. Browse to your vorlonjs folder you created (example: cd /c/dev/vorlonjs)
    3. Now we are going to use the commands from azure to add files to git
      1. git init
      2. git add .
      3. git commit –m “initial commit”
    4. Again copying right from azure to add remote repository and commit
      1. git remote add azure (this line will be in your azure account)
      2. git push azure master
        1. If need be use reset deployment credentials
      3. Enter your password
  2. When it’s done it should now say “Active Deployment”
  3. Go to dashboard / URL
  4. First time it loads it may error out, just refresh it
  5. That’s it!

 

Installing Windows 10 IoT on Raspberry Pi 2 from Windows 8

So you have a Raspberry Pi 2 and want to install Windows 10 IoT on it but don’t have a machine running Windows 10? No problem. These instructions will guide you through how to accomplish this.

It is important to note that this is not the “official” way to install it. These instructions allow you to do the install from a machine running Windows 7 or Windows 8/8.1.

With that said continue at your own risk! 🙂

Tools I am using today 

  • Raspberry Pi2
  • Microsoft Surface Pro 3
  • Sandisk 64gb Class 10 MicroSD Card
  • Targus USB SD Card Reader
    • Even though the Surface Pro 3 has a MicroSD slot, I had to use the external reader for the software used in the install to recognize the card properly

Installation Instructions

  • Login to  http://connect.microsoft.com using your Microsoft Account
  • Go to Directory -> Windows Embedded -> Join “Windows Developer for IoT” program

microsoft-connect-win-10-iot-program

  • Once joined, go to downloads and download Windows 10 IoT Core Insider Preview Image for Raspberry Pi 2
  • At the time of this post the latest build is 5/12/2015
  • From here you can download the zip directly or use the Microsoft File Transfer Manager

windows-iot-core-download

  • We now need to download three more utilities so that we can do the install from Windows 8 or Windows 7
    • SD Formatter – I always format my SD card before starting
    • ImgMount – This lets you mount the image and create a VHD from the mounted image.
    • WinImage – This program lets you write the VHD to an eternal drive
  • I took everything and copied to one folder on my machine to make things easier. In the example I named it c:\w10iot

w10iot-folder

  • Extract the Windows 10 IoT zip file once downloaded
    • The only file we are going to work with today is Flash.ffu
  • Launch an administrative command prompt and browse to c:\w10iot
  • Run the following command “imgmount flash.ffu”

windows-10-iot-create-vhd

  • Windows+X and go to “Computer Management”
    1. Go to Disk Management
      1. You should see an additional drive, right click on it and “detach it”
      2. Make sure to note the folder where the VHD is located
        1. I copied and pasted this into a notepad
      3. Move the file into your c:\w10iot folder

windows-10-iot-detach-vhd

windows-10-iot-vhd-location

  • Install WinImage
    • No license code is needed. It comes with a free 30 day trial. Of course if you like the software I encourage you to purchase it!
  • Plug your MicroSD card in
    • Again; I do this using the reader
  • Install SD Formatter and format your card
    • I use the following options
      1. Format Type – FULL (Erase)
      2. Format Size Adjustment – OFF

windows-10-iot-sd-format-options

  • Launch WinImage (administrator)
  • Go to Disk -> Restore Virtual Hard Disk image on Physical Drive

win-image-export

  • Choose your MicroSD card drive

win-image-select-disk

  • Select your VHD

win-image-select-vhd

  • It will warn you and then start the process
  • Depending on your hardware it should take about 5-10 minutes

win-image-progress

  • Once its done place the MicroSD card in your Raspberry Pi2 and boot it up!
  • The install will take a while.

windows-10-iot-setup windows-10-iot-first-boot

  • That’s it! Happy developing!

windows-10-iot-setup-complete

Free Web Development Courses

Some of the most common questions I get from new developers is “How do I get started?” and “Are there free resources online for me to learn?“. The good news is that it is very easy to get started and Microsoft Virtual Academy is a phenomenal free resource online with hundreds of courses.

If you are just getting into web development I highly recommend visiting Web Development Courses and Beginner Courses to browse all the free courses Microsoft Virtual Academy has to offer. Simply register on the site to get complete access to the videos, course materials and example code.

There are many to choose from and they guide you from basic HTML to launching Web Apps using Microsoft Azure. Head on over and happy learning!