Introduction to ASP.NET

The C# Programming Language is not only used for client-side, desktop, and offline applications. C# is also one of the preferred languages when building server-side applications or applications that are hosted on a remote or local server. A typical workflow that involves server-side applications is when a user uses a client such as a web browser to submit information to a server. This is typically a web form with inputs such as textbox and selection lists. When the information is submitted to the server, the server determines what server-side application should process it. It is then processed by a server-side application and produces an output that will be sent back to the user's client. One of the most popular technologies where C# is used for server-side development is ASP.NET.

ASP.NET is a web application framework that uses the power of .NET to accept web requests from a client and dynamically produces a web response that will be sent back to the client. The ASP.NET framework is a server-side framework which means this only needs to be installed on the server or in our case, our development machine. Although you can use ASP.NET to request any type of data and files from the server, the typical type of file or output you request from it is an HTML document or web page. The user only needs a web browser or any client software capable of recognizing and rendering the HTML output produced by ASP.NET. ASP.NET is an open-source framework which means you can see its source code if you are curious enough on what is happening behind the scenes.

ASP.NET originated way back before .NET was even introduced. The term ASP comes from the technology it replaced now called "classic ASP" or "Active Server Pages". When .NET was born, Microsoft needs a new framework for web and server-side development. Hence, ASP.NET was born which can take advantage of the full .NET framework library. When ASP.NET was first introduced, it's only way of creating dynamic web pages is by creating web forms. Web forms were based on windows forms and allow visual programming of web pages where you simply drag and drop controls on a designer just like windows forms. It was a choice made by Microsoft as there were too many windows forms developers back then and they can take advantage of it to attract them to try ASP.NET as they will already be familiar on its workflow. As time passes, challenges were encountered when using web forms. One main problem when using it is the separation of User Interface code with business logic code. This makes unit testing hard as the business logic is tightly coupled with the user interface. Microsoft introduced ASP.NET MVC which uses the Model-View-Controller architectural pattern which encourages separation of concerns by dividing your code into 3 distinct layers, each with individual responsibility.

I already mentioned ASP.NET Web Forms and ASP.NET MVC. These two are technologies on their own that sit on top of the core ASP.NET code. The ASP.NET is composed of a set of server-side technologies and the image below illustrates all of them.

The ASP.NET Family of Technologies

  • Web Forms - Used for building web pages using web forms
  • Web Pages - Allows the creation of simple dynamic pages using the Razor view engine
  • Single Page Apps - A single web page that uses asynchronous javascript request to the server and update the UI.
  • MVC - Uses the Model-View-Controller pattern to serve web pages
  • Web API - Allows the creation of restful web services that can serve data (typically in JSON format) to be used by any client-side software.
  • SignalR - Used in real-time communication with the server and the client.

As we can see in the diagram, the first four technologies are all aimed at creating web applications. The last 2 are aimed at creating web services.  We will be using ASP.NET MVC in our tutorial as I believe that this is a better a maintainable way to create web applications with ASP.NET. ASP.NET Web Forms is still being supported by Microsoft as of today, but it is now only recommended to be used for maintaining old projects that uses web forms and too big to migrate to MVC.

The latest major version of ASP.NET is version 5 and currently, it is still in beta stage. A lot has changed in this release since version 4 and even if you already know ASP.NET, there is a lot of new concepts to learn in ASP.NET 5. ASP.NET and MVC is versioned separately. Currently, MVC is at version 6. I will use these latest versions of ASP.NET and MVC in the following tutorials.