Static files
One of the main features of ASP.NET Core is that it can be as lean as you like. This means, you are responsible for what you’re going to put into the application, but it also means that you can make the application very simple and fast.
In fact, if you start your project from an empty ASP.NET Core web application template, the application will not be able to serve static files. If you want to do it, you have to add and configure a specific package. A common question is “Why doesn't it support static files by default if all websites need static files?" The truth is that not all the websites need to serve static files, especially on high-traffic applications. In this case, the static files should be hosted by a content delivery network (CDN). Moreover, your web application could be an API application that usually serves data using JSON or XML format instead of images, stylesheets, and JavaScript.
Configure static files
As you’ll see, most of the configurations are managed by middleware components available on NuGet. That’s also true in this case; you have to install a specific package and configure its middleware. The package to install is Microsoft.AspNetCore.StaticFiles. You can get it using the Package Manager. You are almost ready. The last but still important thing to know is that the wwwroot folder present in the root of your project will contain all the static files. So, if you want to serve a file called image1.jpg for the request http://localhost:5000/image1.jpg, you have to put it into the root of the wwwroot folder, not in the root of the project folder like you were doing with the previous version of ASP.NET.
Single page application
Another scenario where the static-file middleware components combined with ASP.NET Core application could be very useful is for a web app that is a single page application (SPA). The best way to describe the meaning of SPA is via Wikipedia's definition-
"A single-page application (SPA) is a web application or website that fits on a single webpage with the goal of providing a user experience similar to that of a desktop application."
Basically, most of the business logic is present on the client. The server doesn't need to render different Views; it just exposes the data to the client. This is available thanks to JavaScript (combined with modern frameworks like Angular, React, Aurelia) and a set of APIs (in our case, developed with ASP.NET MVC Core).
If there is no server-side rendering, the web server must return a static file when the root domain is called by the browser (http://www.mysite.com). To do that, you have to configure the default documents into the Configure method of your Startup class.
For demonstrating this, we first need to create a blank or empty project of .NET Core applications. For this, just open the Microsoft Visual Studio 2017 as below.