ASP.NET Core

How does ASP.NET Core processes a request?

In this post, I’ll explain how a request comes into the ASP.NET Core web server and how it returns a response to the browser.

If you are aware of how ASP.NET Core processes a request, you can skip reading this article.

The request cycle

ASP.NET CORE request cycle: imitated from the diagram in ASP.NET Core in Action book

When the user tries to access the URL from a browser, the request is sent to a server which then sends it to our reverse proxy server.

As you can see from the above diagram, we first have the reverse proxy intercepting the request before sending it over to the ASP.NET Core web server. We can use the reverse proxy to increase performance, security, load balancing etc.

The request is now forwarded to the ASP.NET Core Web server. Kestrel is the default built-in web server for ASP.NET Core applications.

The responsibility of the Kestrel is to construct a HttpContext object from the raw request data. This object will have details required to create appropriate response to the request.

After processing the application logic, it will return the response to the web server.

The ASP.NET Core web server will convert the response from the application logic into a raw HTTP response and sends it back to the reverse proxy. The reverse proxy will then send it back to the browser.

What is a reverse proxy and why we need one?

A reverse proxy is a proxy that sits in front of the one or more web servers, intercepting the requests.

We don’t want our ASP.NET Core server to handle every type of request from the internet. An example would be if we implement a CDN to server static files when requested for static content, then attacker(s) would target the reverse proxy (in this case the CDN) instead of our server.

Advantages of having a reverse proxy:

  • Load balancing
  • Protection from attacks (DoS)
  • Caching
  • Static content serving
  • API Gateway
  • URL rewriting
  • decoupling the application from the underlying operating system

What is Kestrel web server?

Kestrel web server is a cross-platform open-source web server for ASP.NET Core.

Kestrel is based on Libuv library, the same thing used by NODE.js. Kestrel only uses Libuv for asynchronous I/O work and supports running multiple event loops.

The most important reason Microsoft built kestrel is to provide cross-platform web server which does not rely on System.web and a full version of CLR for bootstrapping the execution environment.

References

Disqus Comments Loading...
Share
Published by
Karthik Chintala

Recent Posts

2 Good Tools To Test gRPC Server Applications

In this post, we’ll see how to test gRPC Server applications using different clients. And… Read More

11 months ago

Exploring gRPC project in ASP.NET Core

In this post, we'll create a new gRPC project in ASP.NET Core and see what's… Read More

1 year ago

Run dotnet core projects without opening visual studio

In this blog post, we’ll see how to run dotnet core projects without opening visual… Read More

1 year ago

Programmatically evaluating policies in ASP.NET Core

Programmatically evaluating policies is useful when we want to provide access or hide some data… Read More

1 year ago

Multiple authorization handlers for the same requirement in ASP.NET Core

We saw how we could set up policy-based authorization in our previous article. In this… Read More

1 year ago

Policy-Based Authorization in ASP.NET Core

What is policy-based authorization and how to set up policy-based authorization with handlers and policies… Read More

1 year ago

This website uses cookies.