So speichern Sie ein Objekt in einem Cookie im asp.net-Kern

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: So speichern Sie ein Objekt in einem Cookie im asp.net-Kern

by Anonymous » 29 Dec 2024, 06:48

Ich habe eine Klasse, die ich als Antwort-Cookie speichern möchte.

Code: Select all

public IActionResult Get()
{
var data = JsonConvert.SerializeObject(new DeviceModel
{
Group = "TEST"
});

HttpContext.Response.Cookies.Append("dv-v3", data);

return Ok();
}

public class DeviceModel
{
[JsonProperty(PropertyName = "g")]
public string Group { get; set; }

[JsonProperty(PropertyName = "platform")]
public string Platform { get; set; }
}
Der codierte Wert wird jedoch im Cookie gespeichert.

Code: Select all

dv-v3=%7B%22g%22%3A%22TEST%22%2C%22platform%22%3Anull%7D; path=/
Image

Ich möchte, dass der Cookie-Wert so aussieht:

Code: Select all

{"g":"TEST","platform":null}
Wie kann ich das im asp.net-Kern tun?

Top