This chapter covers
- Using cookies to store data that will be presented in subsequent requests
- Using sessions to identify related requests and store associated data
- Working with HTTPS requests
- Limiting the rate of requests processed by endpoints
- Responding to exceptions and errors
- Filtering requests based on the host header
In this chapter, I continue to describe the basic features provided by the ASP.NET Core platform. I explain how cookies are used and how the user’s consent for tracking cookies is managed. I describe how sessions provide a robust alternative to basic cookies, how to use and enforce HTTPS requests, how to deal with errors, and how to filter requests based on the Host header. Table 16.1 provides a guide to the chapter.
Table 16.1 Chapter guide (view table figure)
Problem |
Solution |
Listing |
---|---|---|
Using cookies |
Use the context objects to read and write cookies. |
1–3 |
Managing cookie consent |
Use the consent middleware. |
4–6 |
Storing data across requests |
Use sessions. |
7, 8 |
Securing HTTP requests |
Use the HTTPS middleware. |
9–13 |
Restrict the number of requests handled by the application |
Use the rate limiting middleware |
14 |
Handling errors |
Use the error and status code middleware. |
15–20 |
Restricting a request with the host header |
Set the AllowedHosts configuration setting. |
21 |