Please enable JavaScript.
Coggle requires JavaScript to display documents.
ASP.net core, NHỮNG FILE ĐÃ BIẾT TRONG ASP.NET CORE, Configuring logging…
ASP.net core
project file
-
while creating a project in visual studio, it creates a project file for us. If you are using C# as the programming language then it will create the project file with the “.csproj” extension.
- Trong project file (MyFirstCodeApplication.csproj) có 1 element <TargetFramework> chứa net5.0 - net5.0 is the new Target Framework Moniker (nickname) (TFM) for .NET 5.0.
- Giả sử khi ta sử dụng 1 gói nuget packages bất kì trên mạng thì nó đc add vào trong project file này
Main Method
Program.cs. contains a public static void Main() method is the entry point for that console application execution and the ASP.NET Core Web Application initially starts as a Console Application
- Và khi CreateHostBuilder(args).Build().Run(); run => Một ứng dụng asp.net core web app được tạo ra từ đây - sau khi đã configured and run/start starts listening to the incoming HTTP requests. :warning:
Trong main Method này có CreateHostBuilder() method
- the CreateHostBuilder() method returns an object that implements the IHostBuilder interface. The Host is a static class that can be used for creating an instance of IHostBuilder with pre-configured defaults.
(Bước này trở xuống là đang setting up the host)
- The CreateDefaultBuilder() method creates a new instance of the HostBuilder with pre-configured defaults. Internally, it configures Kestrel (Internal Web Server for ASP.NET Core), IISIntegration, and other configurations.
What are the Tasks performed by CreateDefaultBuilder() method?
(CreateDefaultBuilder thực thi 3 nhiệm vụ chính)
1. Setting up the webserver
- an ASP.NET core Web application can be hosted in two ways
- InProcess hosting (default)
- (InProcess hosting which is used for hosting the application in IIS or IIS Express) - chỉ 1 loại này
How to Configure InProcess hosting in ASP.NET Core?
(just add the <AspNetCoreHostingModel> element to value is InProcess)
- OutOfProcess hosting
(gồm 2 loại webserver)
-
2. One external web server. (reverse proxy server)
(cái này như 1 cái lớp bảo vệ internal web server /kestrel thôi)
the external web server can be IIS, Nginx, or Apache. (có thể là các server khác nhau)
- nhớ kỹ - the external web server may or may not be used. nó còn được gọi là reverse proxy server
- mục đích dùng external web server là:
This is because the reverse proxy server provides an additional layer of configuration and security which is not available with the Kestrel Server. It also maintains the load balancing. So, it is a good choice to use Kestrel Server along with a reverse proxy server.
Đọc kỹ
Sử dụng OutOfProcess hosting
bằng cách chèn đoạn code sau: AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
As we have configured the Out of Process hosting model, now the IIS Express acts as a reverse proxy server and Kestrel acts as the internal webserver.
Now, the IIS Express receives the incoming HTTP request and then forwards it to the Kestrel Web Server for processing. The Kestrel Web Server processes the request and sends the response back to the IIS Express which in turn sends the response back to the client i.e. to the browser.
đọc thêm
What happens when we run the ASP.NET Core application using .NET Core CLI?
- When we are running our application using.NET Core CLI, then by default, it ignores the hosting setting that you specified in the application’s project file i.e. csproj file. So, in that case, the value of the AspNetCoreHostingModel element is going to be ignored.
The .NET Core CLI always uses OutOfProcess Hosting Model and Kestrel is the webserver that will host the ASP.NET Core application and also handles the HTTP requests.
.NET Core CLI - sẽ mặc định sử dụng OutOfProcess hosting mode and Kestrel
đọc thêm
Tại sao sử dụng Kestrel?
Ứng dụng ASP.NET cũ thường dính chặt vào IIS (Internet Information Service). IIS là một web server với tất cả các tính năng đầy đủ cần có. Nó được phát triển từ khá lâu và rất trưởng thành, nhưng nó cồng kềnh và nặng. Nó trở thành một trong những Web server tốt nhất ở thời điểm hiện tại nhưng nó cũng là một trong những thứ chậm nhất.
SP.NET dính chặt vào IIS cũng là gánh nặng cho IIS.
Thiết kế mới của ứng dụng ASP.NET Core giờ đây hoàn toàn tách rời khỏi IIS. Điều này tạo cho ASP.NET Core có thể chạy trên bất cứ nền tảng nào. Nhưng nó vẫn có thể lắng nghe các HTTP Request và gửi lại response về cho client. Đó là Kestrel.
Nguồn: TEDU
Why InProcess Hosting Gives Better Performance that the OutOfProcess Hosting Model?
(hiểu cái này để biết tại sao InProcess Hosting được lựa chọn hơn)
giải thích:
With the InProcess hosting model, there is only one web server i.e. IIS. So, in the case of the InProcess hosting model, we do not have the performance penalty (bất tiện) for navigating the requests between the internal and external web servers.
(nghĩa là chúng ta ko có cái sự bất tiện về mặt thời gian - MẤT THỜI GIAN cho việc điều hướng những request giữa 2 websever). NÊN LÀ:
This is the reason why the InProcess hosting model delivers(=give) significantly higher request throughput(lượng) than the OutOfProcess hosting model.
- Loading the host and application configuration from various configuration sources (will discuss in our upcoming articles)
có 2 loại Startup Class
- While setting up the host, the Startup class is also configured using the UseStartup() extension method of the IHostBuilderclass.
đọc
- khi đang cấu hình main method thì cái Startup Class này sẽ chạy đầu tiên - ko tin thì vào program.cs xem đi
Startup Class này giống như Global.asax ngày xưa vậy là file chạy đầu tiên nhất !
-
-
Quan trọng - Mục đích của cùng của những công việc này là để làm ứng dụng trở thành ASP.NET CORE Web application và có thể lắng nghe YÊU CẦU TỪ PHÍ HTTP
-
- Configuring logging (will discuss in our upcoming articles)
-