Skip to content

Response.Cookies.Append cannot set cookie value without encoding #36992

@peacecwz

Description

@peacecwz

Describe the bug

I cannot append cookie value without encoding. We are migrating old legacy systems (.NET Framework) to .NET 5 but Response.Cookies.Append function is encoding cookie value. I can set cookie as header but I need to build cookie header value manually (I cannot use CookieOptions feature. SameSite, Expires, Domain or Path ...)

Idea suggestion

NodeJS Express can do this like this with "encode" options
You can check it http://expressjs.com/en/api.html#res.cookie

To Reproduce

It's example action for setting encoded cookie in .NET 5. As same example it works in .NET Framework

        public IActionResult Index()
        {
            Response.Cookies.Append("IndexPage", "tx=1&ty=2");
            return View();
        }

It's output

Set-Cookie: IndexPage=tx%3D1%26ty%3D2; path=/

Further technical details

.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.1.21103.13
 Commit:    b8a03527b2

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.6
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100-preview.1.21103.13/

Host (useful for support):
  Version: 6.0.0-preview.1.21102.12
  Commit:  9b2776d481

.NET SDKs installed:
  3.1.302 [/usr/local/share/dotnet/sdk]
  5.0.100 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.1.21103.13 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.1.21103.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-preview.1.21102.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: DuplicateResolved as a duplicate of another issueStatus: Resolvedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions