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

Ein Treffpunkt für C#-Programmierer
Anonymous
 So speichern Sie ein Objekt in einem Cookie im asp.net-Kern

Post by Anonymous »

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?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post