Microsoft Azure Web Apps - My first one.
So, I've decided to attempt to write down 'stuff what I do', one so that I've got a record of problems I've come across and their solutions and two as an advert for 'stuff what I do' of course... I'm only human.
Having done an amazing Introduction to Microsoft Azure for Developers course in January with QA, I highly reccommend it, I decided to get to grips with building an MVC Asp.net Core web app and hosting it on Azure.
As you may or may not know, Asp.net Core is the latest version of .Net. From what I understand it's completely been rebuilt from the ground up. I first came across it when I attended some informal training at Microsoft, where it was then called vNext. The general concept appears to be that they've completely shrunk the .Net framework so that it can work on practically anything... at least that's how it was sold to me.
Now renamed as .Net Core, depending on what features you want out of the box you can run it on Linux, OSX and pretty much anywhere. I've been using the MVC framework fro a few years now and was really intrigued by this rebuild of the .Net framwork and have elected to dive in 'feet first'. It's been a bit of a tough ride so far, mainly as the documentation is, shall we say 'fluid'.
It can be a bit of a traumatic journey, Asp.net Core, as exhibited by my following of an official tutorial whereby the code just wouldn't work. The framework kept complaining that the functions I had been calling didn't exist. It was only a lengthy search that hi-lighted the fact that the code I'd been using had changed in the new version of Asp.net Core. But, at the end of the day I'm actually finding it quite an enjoyable experience.
Anyway, I digress, back to Azure Web Apps. I've had now, Shared .Net Hosting with TSOHost (awesome company). Which has been great, but limiting, due to the 'Shared Hosting' bit. Having tried to implement an Asp.net Core web app on my shared hosting plan, but finding that it wasn't yet available on the platform, I decided to migrate the App to Azure.
One of the things that was stopping me from moving my Web Apps to Azure was my perception of the cost. Much as I love the Azure platform, it's incredibly difficult to actually work out how much something is going to cost and what features you need or get.
I'd been under the impression that what you got with an Azure Web App plan was one Web App per plan. To explain, with Azure Web Apps you get several options Free, Shared, Basic, Standard and Premium. As you'd expect, each plan comes with various limitiations and I was under the impression that I needed a seperate plan per Web Application I wanted to host... turns out that that's not the case. Basically, depending on the plans, you can hoof as many Web Apps as you can fit on the space allocated, so long as your resources allocated can cope with it. As such, with a little bit of massaging, an Azure Web App plan can be unbelievably cost effective, especially when you take into account how cheap Azure Storage is.
The general idea is, move all content, other than your Views, Controllers etc onto Azure Storage, apparently this is even more cost effective if you host your Web App and Storage in the same location. So this is what I've done. I've got an Azure Storage account that has the following containers: Images, Audio, Video, Movies. I've kept these general as I'm likely to have content that can and will be used by more than one Web App. Each Web App then has a container named after the Web App and suffixed with -assets. Thus Web App A will have a container A-assets. The assets will contain the css and Javascript etc. After setting this up, the general idea is that you apply a CDN to deliver this content. I've not yet set that bit up and am just serving using the direct urls to the content.
So, I set this up, changed my original app accordingly and it works beautifully when debugged via Visual Studio 2015 on my Laptop. Awesome, and I'm presuming that as I'm deploying a Microsoft Technology, via a Microsoft SDK to a Microsoft Host that all I'm going to have to do is add my Azure credentials, press publish and Bob's your uncle (or in my case my Dad). This I do and immediately get a 500 error. After a bit of searching and a quick examination of my log files I'm none the wiser.
So, I desperately search and luckily find the following gem.
StackOverflow - project.json settings
EDIT2: I realized why appsettings.Development.json wasn't getting published, it wasnt in my project.json's publishInclude section...
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"appsettings.Production.json",
"web.config"
]
},
I had a barebones implementation which looked like the above but only with 'wwwroot' and 'Views' and nothing else. I basically added the rest, re-published and all is well. I kind of like this, the fact that a couple of added lines to a json file can do the trick. To me that is the really interesting thing with Asp.net Core, everything, as far as I can tell is configurable, and I mean everything.