A cookie is added to Response.Cookies is also added to Request.Cookies. Any way to get the original Request.Cookies?

If I add a cookie to the response via Response.Cookies.Add() , the cookie will also appear in Request.Cookies .

Is there a way to get the original request cookies (ignoring recently added cookie responses) without first caching Request.Cookies in advance?

There is another question that asks why this situation exists (the point I'm talking about). I ask if there is any way there.

Update

As a very crude filter, you can search for cookies in Request.Cookies whose Expires is equal to default(DateTime) . This is because when browsers serialize their cookies in a request, they do not include their expiration dates.

However, this will not save you any cookies accidentally added to Response without Expires .

+4
source share
1 answer

Request.Headers["Cookie"] contains the original header value sent by the browser. This is a comma-separated list of key-value pairs .. For example,

 key1=value1; key2=value2 

What can be analyzed with Dictionary<string, string> to find out the source request cookies (ignoring any that were added or changed by controlling Request.Cookies or Response.Cookies ).

(Values ​​are encoded in a URI to avoid Bobby Tables situations for values ​​containing the same signs or semicolons.)

+2
source

Source: https://habr.com/ru/post/1382399/


All Articles