dotnet / dotnet/aspnetcore

Not able to read cookie value with more specific path in .NET Core/5.0?

Open
#37,431 16 comments 0 reactions 0 assignees View on GitHub
area-networking feature-http-abstractions investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

It appears `HttpCookie` has been completely removed in .NET Core/5.0.

Moreover, if two cookies have the same name but different paths (let's say one path is */Folder* and one path is */Folder/Subfolder*), it seems to return the value for the cookie with the shorter path. This appears to run counter to at least the spirit put forth in [RFC 6265](https://www.rfc-editor.org/rfc/rfc6265), which in section 5.4, subsection 2 states:

> The user agent SHOULD sort the cookie-list in the following order:
>
> Cookies with longer paths are listed before cookies with shorter paths.
NOTE: Not all user agents sort the cookie-list in this order, but this order reflects common practice when this document was written, and, historically, there have been servers that (erroneously) depended on this order.

In my case, I am storing cookies using the path of the current page. But I just moved a page from */Folder* to */Folder/Subfolder*. And, because users will have cookies stored in the shorter path, .NET now provides no means for accessing the value with the more specific path. My code is broken and I don't see any workaround.

Shouldn't `Request.Cookies[key]` at least return the first matching value?

I just don't get the thinking behind the removal of this feature.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.