Asp.Net core requests

What are we doing


GET /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
					

HTTP/1.1 200 OK
Date: Thu, 10 Jun 2021 05:59:09 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

Hello World
					

There are two aspects to this

  • What processing should be preformed on each request type?
  • How are requests accepted into the system?

Processing is handled by

  • By defining a Pipeline which is composed of
  • Middleware
  • Controllers
  • Filters
  • Actions

The Pipeline

  • Built using IApplicationBuilder
  • Defined by us in Startup.cs

Middleware

  • Occurs for all requests
  • You have access to the requests http context containing the header and footer

app.Use( async (context, next) => {
	await context.Response.WriteAsync("M1.1");
	await next.Invoke();
	await context.Response.WriteAsync("M1.2");
});
					

app.Run( async (context) => {
	await context.Response.WriteAsync("M2.1")
});
					

Routing

  • Is middleware
  • Passes the request to the Action Invocation pipeline
  • With mvc the request is passed to a controller

Controllers

  • Intended to perform the main request processing
  • Filters - Across many requests.
  • Actions - Perform the main request.

Hosts

  • Requests are accepted into the system via Hosts
  • Filters - Across many requests.
  • Actions - Perform the main request.