Click here to Skip to main content
15,615,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used set cookies and get cookies

// set cookie
 HttpCookie cookie = new HttpCookie("uid");
                cookie.Value =user.ID;
                cookie.Expires = DateTime.Now.AddDays(1);

//get cookie in ashx file

HttpCookie cookie = context.Request.Cookies.Get("uid");
string id = cookie.Value;

In the above code first i have set cookies, but when i try to get cookies value in ashx file(see in the below code) then cookie object is null while this can run easily in aspx file but null in ashx file.
Updated 29-Jan-12 20:33pm
Abhinav S 30-Jan-12 2:33am    
Code tags added.

1 solution

If ashx page is not calling before the assign the cookie value
then you can try this
HttpCookie cookie =(HttpCookie)HttpContext.Current.Request.Cookies["uid"];
string id = cookie.Value;
Share this answer
Anuja Pawar Indore 30-Jan-12 5:15am    
Added pre tag

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900