how do i set multiple cookies from an azure function?

As you didn’t provide how the variable cookies be initialized in your code, so I can’t reproduce your problem. But I test with my code in my function, it works fine. You can refer to my code below:

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Net.Http.Headers;

public static async Task<HttpResponseMessage> Run(HttpRequest req, ILogger log)
    var resp = new HttpResponseMessage();

    var cookie1 = new CookieHeaderValue("name1", "content of cookie==1111");
    cookie1.Expires = DateTimeOffset.Now.AddMinutes(1);
    cookie1.HttpOnly = true;
    cookie1.Path = "/l/";

    var cookie2 = new CookieHeaderValue("name2", "content of cookie==2222");
    cookie2.Expires = DateTimeOffset.Now.AddMinutes(1);
    cookie2.HttpOnly = true;
    cookie2.Path = "/l";

    var cookie3 = new CookieHeaderValue("name3", "content of cookie==3333");
    cookie3.Expires = DateTimeOffset.Now.AddMinutes(1);
    cookie3.HttpOnly = true;
    cookie3.Path = "/l/some-folder-path";

    resp.Headers.AddCookies(new CookieHeaderValue[] {cookie1, cookie2, cookie3});

    return resp;

After request the function in my browser, we can see the cookies in below screenshot: enter image description here


enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top