liveBook · Manning

Deletion

As explained in Pro ASP.NET Core 7, Tenth Edition

Delete is a response-cookie operation that instructs the client to remove a cookie.

Use `context.Response.Cookies.Delete(name)` to instruct the browser to remove a named cookie. This is a response operation: the browser stops sending the cookie on subsequent requests. Call it before writing the response body, because cookie changes are sent in response headers and later changes are ignored. section 16.2

Clear two counters

A `/cookie` endpoint reads `counter1` and `counter2` from request cookies, defaults missing values to zero, increments them, and writes them back with a 30-minute `MaxAge`. A `/clear` endpoint calls `context.Response.Cookies.Delete("counter1")` and `Delete("counter2")`, then redirects to `/`. Visit `/cookie` again to see the counters start over. section 16.2

...
app.MapGet("clear", context => {
    context.Response.Cookies.Delete("counter1");
    context.Response.Cookies.Delete("counter2");
    context.Response.Redirect("/");
    return Task.CompletedTask;
});
...

Shows the two `Delete` calls and the redirect in the `/clear` route. section 16.2

Do not confuse this with an HTTP DELETE request to an API. An API action can use DELETE to remove a database object by key; `Response.Cookies.Delete` instead changes the cookies sent to a browser. section 19.4.2 section 16.2

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Shows the `Delete` calls, redirect, and response-header timing; does not detail browser cookie-removal mechanics.
Examples
Tests `/cookie` and `/clear` to observe incrementing counters reset after both cookies are deleted.
What it assumes
Builds on ASP.NET Core request and response handling while demonstrating cookie reads and writes in endpoint code.
What you can do after
Apply it via `Response.Cookies.Delete` to clear named cookies before writing the response body.
How it connects
Connects deletion to request cookies, response cookies, `CookieOptions`, redirects, and response headers.

Also explained in

Compare how 8 books explain deletion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.