Looking at the Solution Explorer, notice that the folder structure and the files are very different from the previous version of ASP.NET. First of all, there is a wwwroot folder, which contains all the static files. As we can see, the solution’s structure differs little from what we are used to seeing. The first thing which we notice is that we use the new special files global.json and project.json. The project.json file contains all the information that the CLI needs to run your project. The global.json file is used to configure all the projects within a directory. It includes just two default sections- the projects section and the SDK section. The projects property designates which folders contain source code for the solution. By default, the project structure places the source files in a src folder.
In a different section, we will explain how to use wwwroot folder and the reason why you need it.
All the files in the root of the project are either the new additions or they changed their role
- Program.cs is the entry point for the Web Application; everything starts from here. As we mentioned in the chapters before, .NET Core host can only run console Applications. Thus, the Web app is a console Application too.
- project.csproj is an XML-based project configuration file. It contains all the package references and the build configuration.
- Startup.cs is not exactly new. If you already used OWIN, you probably know the role of this class, but we can definitely say if the Program.cs is the entry point of the .NET Core app, Startup.cs is the entry point of ASP.NET Core Application (previously we were using the global.asax file).
- web.config is still here, but it's almost empty and only used to tell Internet Information Service (IIS) to process all the requests, using ASP.NET Core handler.
Program.cs
As mentioned before, this class is the entry point of .NET Core Application and its role is to create the host for the Web Application. Since we can host our Web Application on different Web Servers with .NET Core, this is the right place to configure everything.
Startup.cs
The ASP.NET Core pipeline starts here. As you can see from the code given below, almost nothing comes with the template. What’s important here are the methods ConfigureServices, where Dependency Injection is configured (we’ll talk about this later in the chapter) and configure, where all needed middleware components are registered and configured. It is app.Run method, which is a perfect example of an inline middleware component. In this case, it is useless because the Web Application will always return the text string "Hello World!", but more complex logic (i.e. authentication, monitoring, exception handling and so on) can be added.
Startup class
Startup class is absolutely the most important class in your Application because it defines the pipeline of your Web Application and it registers all the needed middleware components. Because of this, it might be very complex with lots of lines of code. If you add checking for the environment, everything can be more complicated and difficult to read and maintain. For this reason, ASP.NET Core allows you to use different startup classes- one for each environment; you want to manage or one for different "configure" methods. The method .UseStartup<Startup>() is very clever. It can switch between different classes automatically, if you are following the right convention (method name + environment name). For example, if you duplicate the Startup class and rename it StartupDevelopment, the extension method will automatically use the new one in the development environment. You can use the same convention for the Startup class methods. Hence, duplicate the method Configure of the Startup.cs file, call it ConfigureDevelopment and it will be called instead of the original one only in the development environment.