Chapter 5. ASP.NET and MVC
At this point, we know how to create a basic web application in .NET Core. We know how to pull down the bits we need (the dependencies), where everything goes, and how to build a portable app. We can run the web app and see it in a browser.
In this chapter, we’ll learn how to create an ASP.NET MVC web app—a bit more complicated and closer to what you’ll work with in the wild.
There is no source code associated with this chapter; you’ll be creating it.
Creating a Basic MVC Web Application
We’ll start by creating a directory, moving into it, and then creating an MVC web application. This is done by introducing a new option to the dotnet new
command—the --type web
option:
mkdir ~/mvc
cd
~/mvc
dotnet new --type web
Done. We’ve just created a skeleton ASP.NET MVC web app in C#. Next, restore the dependencies (dotnet restore
) and run (dotnet run
) the application. The prompt will point to the URL to browse this basic ASP.NET MVC site at http://localhost:5000.
Accessing the URL from the Windows desktop
If you are running Linux in a command-line environment inside a VM, you’ll need to alter the code in Program.cs to include the following line to make it available outside the VM:
.
UseStartup
<
Startup
>().
UseUrls
(
"http://*:5000"
);
In the browser shown in Figure 5-1, we see the basic MVP web app.
Get Transitioning to .NET Core on Red Hat Enterprise Linux now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.