I’m setting a cookie using a global response filter:
GlobalResponseFilters.Add((req, res, requestDto) => res.SetSessionCookie(“CookieType”, “StarBucks”));
But I can’t read it in a Razor Page. The Cookies Dictionary count is 0:
ViewBag.Title = “ServiceStack with Razor”;
var cookiesCount = this.Response.CookiesAsDictionary().Count;
What I’m I missing?
Thanks in advance
If you want to pass additional info throughout the Request pipeline you should use Request.Items instead. Normally you would check for Cookies on the Request.Cookies but this is only available on the subsequent requests when the client resends the cookie.
In this case I need to set a cookie that will be used by my SS app and another web application so I can’t use the Items dictionary.
So, should I set the cookie in the Request (instead of Response)?
You should set cookies on the response (when it doesn’t already exist) but check for them on the incoming request and when you want to pass metadata in the request pipeline you should use Request.Items.