Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve cookie values in ASHX

It's there a way to retrieve cookie value in ASHX Handler ?

I set a cookie in a page, and I want to retrieve it in my ashx. My cookie is always null.

I save my cookie like this

HttpCookie tokenCookie = new HttpCookie(cookieName);
 tokenCookie.Values["siteGuid"] = authenticationInfo.SiteGuid.ToString();
  HttpContext.Current.Response.Cookies.Add(tokenCookie);

I retrieve my cookie like this

 HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
 return new Guid(cookie["siteGuid"]);

Ok sorry that was my fault. My handler was on a sub domain.

like image 238
Cédric Boivin Avatar asked Feb 22 '26 07:02

Cédric Boivin


1 Answers

If you want to access the cookies across the sub-domain. You might need to assign the domain name for the cookies>

Response.Cookies["domain"].Domain = ".somedomain.com";

Don't miss the .(Dot) before the domain name.

like image 79
Tee Wu Avatar answered Feb 23 '26 20:02

Tee Wu