GetTypedHeaders().SetCookie in .net core

Karthik K V 1 Reputation point

Team, I am trying to access the response cookies in a result filter - OnResultExecuted like

var setCookieHeaderValues = context.Response.GetTypedHeaders().SetCookie;

I also tried using the OnStarting delegate on context.HttpContext.Response, however it never returns the cookies which are in set-cookie rather it is always returning an empty object. Am I missing something here? Please help.

Note, that I can see the response cookies in the chrome - dev tools 1) Application - Storage - Cookies and 2) Network - Cookies - Response Cookies

A set of technologies in the .NET Framework for building web applications and XML web services.
3,159 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Wang-MSFT 1,046 Reputation points

    Hi, @Karthik K V ,

    You could try coding as below :

    Codes of MyActionFilterAttribute :

    public class MyActionFilterAttribute : ActionFilterAttribute  
        public override void OnResultExecuted(ResultExecutedContext filterContext)  
            var setCookieHeaderValues = filterContext.HttpContext.Response.Headers;  
            var cookies = setCookieHeaderValues["Set-Cookie"];  

    Codes of HomeController:

        public class HomeController : Controller  
            public HomeController()  
            public IActionResult Index()  
               Response.Cookies.Append("Test", "hellocookie");  
                return View();  

    Test result:


    If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Michael Wang

    0 comments No comments