Developing a ASP.Net web application using .Net core
In my earlier post we had seen how we can create a console application using the new .Net core libraries.
Moving further, we’ll now see how we can use the same .Net core cross platform libraries to develop and run a basic Hello World web application on Linux(I’ll be using Ubuntu 14.04 in this example).
We had already installed Visual Studio Code and .Net core libraries in the earlier post.
We need to now install the following…
Install Yeoman, bower, grunt and gulp using… sudo npm install -g yo bower grunt-cli gulp
Next install the ASP.Net generator using… sudo npm install -g generator-aspnet
With this we are almost ready to create the new web application.
Lets create a new folder for our web application.
We’ll now use Yeoman, to generate the basic structure of the web application.
Output:
For the sake of our example here, we’ll go ahead with the Empty Web Application option.
It will ask us to name this application. Provide some name for the web application and press enter.
Listing contents of this directory will show the following files…
Just like the earlier post example of console application, the Program.cs file has the main method which serves as the entry point for this web application.
Contents of Program.cs
The Startup class, which is part of Startup.cs class is invoked by this main method.
This class by default returns Hello World as part of the response.
Contents of Startup.cs file.
The project.json file is the configuration file for the web application, the contents of which are as follows..
Just like the console application covered in the earlier post, this file has all details related to the .Net core libraries version being used, the Nuget package dependencies, tooling used etc.
We need to use the dotnet command line tools to restore these packages.
Output:
Next we can build the web application using
Output:
If this is successfull, we can now run the asp.net application using
Output:
This uses the cross platform kestrel web server to host the application.
You can now open a browser of your choice and enter the url http://localhost:5000
This will bring up Hello World on to the browser output screen.
While there are a lot of concepts and details behind the steps that we have done above, this was supposed to be a quickstart to just get you up and running asp.net web application on Linux.
You may check out the official documentation of ASP.Net core here
Leave a Comment