3. Creating our Web Site

3.1 Visual Studio scaffolding

In order to create an ASP.NET Core Application, I can simply start Visual Studio 2017 and select File / New / Project from the menu. I know New Web Site sounds tempting but don’t use it; that kind of site doesn’t scale up well once you get to real applications.

I’m taken to the New project dialog box. From the left menu I’ll select Visual C# since it’s the most common coding language for .NET, then Web. In the middle pane I’ll select ASP.NET Core Web Application (.NET Core). In the lower part of the dialog box, next to the Name: label I’ll type the name of my project: Demos.

Now I click the OK button and I’m taken to a second dialog: New ASP.NET Core Web Application (.NET Core). Time to select the features I want. I’ll select Web Application, make sure the Enable Docker Support checkbox is unchecked and authentication is set to Individual User Accounts (if necessary, click the Change Authentication button to select that option). Here’s what that dialog looks like:

Now I click the OK button of the New ASP.NET Core Web Application dialog and that’s it for now; my application is ready. In order to run it inside my browser, I’ll select Debug / Start Debugging from the menu, or use the F5 shortcut:

When I do this, Visual Studio starts a local Web server (IIS Express), runs my browser and points it to the URL of my site on that server, then finally attaches to the running code in debug mode so that it can catch any exception or show the code when I reach a breakpoint.

This is what I get in my browser:

What’s nice is that the site is responsive (the default template uses Boostrap):

That application also has a menu above, with links that take me to almost empty “About” and “Contact” pages. Also note that we already have fully-functional “Log in” and “Register” links for user authentication. If I use them, a local SQL Server database will be created for storage.

Well, we have kind of a nice startup after just a few clicks. Now let’s see some theory before we can extend our application. Don’t worry, I’ll keep it short: this book focuses on getting you up and running quickly.

3.2 Quick facts about that template

This basic application has been configured to use ASP.NET MVC. In short, MVC allows for:

  • Separation of concerns: controllers handle the HTTP request while views generate the outgoing HTML.
  • Testability (easy unit testing of the controllers).

Several folders have been created as part of that initial scaffolding. We’ll see more about them through the book; in short:

  • wwwroot: content that will be available to the client (browser);
  • Data: Entity Framework classes;
  • Model: business classes;
  • Services: dependencies that will be injected;
  • Models: MVC models;
  • Views: MVC views;
  • Controllers: MVC controllers.