LOGIC Library

This site is the Logic involvement in sharing expertise and skills acquired in daily work. The goal is to create a solid knowledge base and share best practices in software development and systems management.

More info about us can be found on logicsistemi.it.

ASP.NET MVC 4 tutorial for web developers - part 2

In this post we'll set up all the tools required to start developing an ASP.NET MVC Project. Base libraries such as .Net Framework and ASP.NET MVC 4 Framework are free, others can be found in a free version or in a more powerful commercial version. What it is sure is that you have to own a Microsoft Windows Operating System.



To start your ASP.NET development you must run a Microsoft Windows operating system. This is the list of operating system and hardware requirements taken from Microsoft website:

Supported operating systems

  • Windows 7 SP1 (x86 and x64)
  • Windows 8 (x86 and x64)
  • Windows Server 2008 R2 SP1 (x64)
  • Windows Server 2012 (x64)

Supported architectures

  • 32-bit (x86)
  • 64-bit (x64)

Hardware requirements

  • 1.6 GHz or faster processor
  • 1 GB of RAM (1.5 GB if running on a virtual machine)
  • 4 GB of available hard disk space
  • 100 MB of available hard disk space (language pack)
  • 5400 RPM hard drive
  • DirectX 9-capable video card running at 1024 x 768 or higher display resolution

For this tutorial we have tried all the code on Windows 7 Home Premium.

The main tool you need in order to start your development is Microsoft Visual Studio. This tool must be purchased, but there is an "Express" edition of it that is free. If you download it from this page, you can select a package that installs the required software development tools and all the required frameworks.

If you already own a Visual Studio copy, on the same page you can find out instructions to install additional required components and, in particular, the ASP.Net MVC 4 framework.

To know the differences between the standard and the Express edition of Visual Studio you can look at this Wikipedia page.

The full package will install also additional tools such as Microsoft SQL Server Express. We will use it in our example, so if you don't have a working version of SQL Server, you have to install it.

The .Net framework version used in our example is the 4.5.

Creating the first application

Visual Studio comes with a set of templates that allow the programmer to easy start different kind of projects.

If you select "New project..." you can find a list of these templates. To start an ASP.Net MVC 4 application select the corresponding template under the C# section.

The additional information you have to specify are related to the application name that is, for this tutorial, MyTasks. Leave all other options at their default value and click the OK button.

After selecting the application type, the required references are automatically set, but Visual Studio offers the possibility to start, not only with an empty application, but also with some code related to the authentication already set up.

In the next windows we can select the "Internet application" template that adds user authentication code based on a standard HTML authentication form. This code is common in every internet application, it is well written an can be customized to get authentication information from different sources.

In one of the following posts we'll customise this code, so this selection we'll be the right one.

The visualization engine we will use is Razor. The approach taken by this engine allows to create HTML pages that are very similar to the PHP or VbScript.ASP pages we are used to write. In particular Razor is structured to allow the mix of HTML and C# code in a very easy way.

We don't need a Unit test project, so we can click on the OK button and let Visual Studio creating our application.

Starting the application

In the next post we will look to the generated code, but, at this moment, we only try to launch the application to see what Visual Studio has already created for us.

In the Visual Studio window click on the debug icon or press F5. This will compile the application and launch your preferred browser to start the debug.

After some second you will see, in your browser window, the homepage of the application with a default page that gives you a lot of information on what to do next.

In this page you will find the following elements:

  • A menu with some links that call actions of the Home controller. We will explain this in the next post!
  • Two links related to user authentication: registration and login. This are links that refer to actions of the Account controller

By clicking on the authorization related links you will find a fully working section that allows you to register to the system, login and logout. User data are stored in a mdf database positioned in the App_Data folder.

Stay tuned for the next chapter with the explanation of the generated code!