We’re going to make a simple .NET web application that can issue something called a Guid back to a user (or client) that asked for it, by hitting a specific web page.
Things we’ll need:
Visual Studio Community edition. I’m using Visual Studio 2015, the latest and greatest will work too.
IIS on your windows machine to test the site out properly before we deploy it to Azure.
Start a new project:
Make sure its an ASP.NET Web Application and call it something useful :
Choose a Web API Template.
WebAPI is a technology which is based on the Model-View-Controller application pattern where, you construct data that sits in the model, controller is where all your business logic sits and the view displays it.
I’m using WebAPI as its scaffolding up a lot of the code for me. Also I don’t have to code up a “view” as I only want to return a json or xml object back with a guid in it.
…this app is only meant to be demonstrating something vaguely useful running…
Change the authentication to No Authentication
I’m not going to host it in Azure yet. Thats for the next article(s).
Let Visual Studio scaffold up some code. After a minute or two a nice page should come up.
I’m not going to go into the subtleties of coding up webAPI apps in this article. What we will do is first delete the values controller and then add a new controller which will create us Guids.
So first, delete the valuesController as we don’t need it:
…and then add a new one, we’ll call it GuidController:
and throw a bit of code in:
public class GuidController : ApiController
// GET api/values/5
public Guid Get()
myGuid = Guid.NewGuid();
Save that, and we should be able to do a build and it not error. Press the green arrow on the top toolbar. On my Visual Studio, it’ll launch Firefox when it attempts to load the website.
Once its compiled, your browser should show you the default front page like this:
To hit our code change the url to this:
(where xxxxx is the random port number Visual Studio came up with for your test site).
You’ll (hopefully) get this:
and there we can see a generated guid. Nice.
One last thing to do in this example, we’ll setup a deployment to the filesystem so that we end up with some deployable code. (I’m pushing this example to my iis hosting folder on my local machine in this example). If I get some feedback from people on twitter I can show how IIS is setup on a later date.
Publish profile easy enough to setup. First create a destination folder on your hard disk (mine was C:\inetpub\wwwroot\simpleGuidAPI)
Back in Visual Studio, go Build > Publish guidAPI
Custom Publish Target:
Think of a name to publish it to (I chose guidPublish):
change the Publish method to File System and input your target location:
Click Publish, and in that folder now exists a compiled version of your web app which we can use in part 2…..
Small Edit…. (8/6/2017)