IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| Redirect URIs and Open Redirect Attacks | IActionResult vs ActionResult | |
HTTP Essentials |
HTTP is a request–response protocol where clients send requests to servers and receive responses. While the body carries data, headers are the metadata that describe how to process, authenticate, cache, compress, and route those messages.
HTTP headers are present on both requests and responses and govern authentication, caching, content negotiation, cookies, CORS, proxies, and more. Some headers are end-to-end (travel from client to origin server), while others are hop-by-hop (apply only to a single transport hop and should not be forwarded). Cookies are also transmitted via headers and enable maintaining application state over stateless HTTP.
GET /api/products?category=books HTTP/1.1
Host: api.example.com
User-Agent: MyApp/1.0
Accept: application/json
Authorization: Bearer <token>
Cookie: sessionId=abc123; theme=light
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 342
Cache-Control: private, max-age=60
ETag: "5f2a-1a6"
Set-Cookie: sessionId=abc123; HttpOnly; Secure; SameSite=Lax
{ "items": [ ... ] }
These families cover how clients and servers exchange capabilities, identities, and constraints, and how intermediaries handle the message across the chain.
The Authorization request header carries credentials to authenticate the client to the server.
Typically, a client first requests a protected resource without credentials, the server replies with 401 Unauthorized and a WWW-Authenticate header indicating acceptable schemes; the client then retries with Authorization.
Common schemes include Basic, Digest, Bearer (tokens like JWT), and others; syntax: Authorization: <scheme> <parameters>.
# Bearer token (e.g., OAuth2/JWT) Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9... # Basic (base64(username:password) over TLS only) Authorization: Basic dXNlcjpzZWNyZXQ=
Cookies are sent by clients using the Cookie header and set by servers using Set-Cookie.
They are commonly used for session continuity and preferences, and include attributes like HttpOnly, Secure, and SameSite to constrain how browsers send and expose them.
# Server to client: Set-Cookie: sessionId=abc123; Path=/; HttpOnly; Secure; SameSite=Lax; Max-Age=1800 # Client to server: Cookie: sessionId=abc123; theme=light
Path and Domain precisely to limit exposure.
The message body (payload) is described by representation headers like Content-Type (media type and charset) and Content-Encoding (compression), while payload headers like Content-Length specify size.
Clients use Accept, Accept-Language, and Accept-Encoding to indicate preferred formats; servers respond accordingly, often with Content-Type and related headers.
# Client requests JSON and gzip Accept: application/json Accept-Encoding: gzip # Server responds with JSON compressed Content-Type: application/json; charset=utf-8 Content-Encoding: gzip Content-Length: 1024
application/json; charset=utf-8).If-None-Match enable conditional requests and caching.
Versioning lets you evolve APIs without breaking clients. Common approaches: URL path (/v1/orders), query parameter (?api-version=1.0), and header-based versioning (e.g., media type negotiation or custom header).
Header-based versioning keeps URLs clean and uses Accept (e.g., application/vnd.example.v2+json) or a custom header like X-API-Version, but requires clear documentation and caching considerations.
GET /orders HTTP/1.1
Host: api.example.com
Accept: application/vnd.example.v2+json
HTTP/1.1 200 OK
Content-Type: application/vnd.example.v2+json
{ "data": "This is version 2 response" }
Cache-Control (e.g., max-age, no-store), validators like ETag/If-None-Match, and Vary to control freshness and revalidation.Access-Control-Allow-Origin, Access-Control-Allow-Methods, and preflight OPTIONS behavior.Location with 3xx status codes.Forwarded or X-Forwarded-For reveal upstream client/protocol information for apps behind load balancers.Range and Accept-Ranges enable partial content delivery for large files and resumable downloads.Content-Security-Policy, Strict-Transport-Security, Referrer-Policy, and X-Content-Type-Options for defense-in-depth.HttpOnly + Secure + appropriate SameSite on cookies.Content-Type and Content-Length (or chunked transfer).Cache-Control, ETag, and Vary intentionally. | Redirect URIs and Open Redirect Attacks | IActionResult vs ActionResult | |