I have the following code:
HttpCookie myCookie = new HttpCookie("PopMsgText");
myCookie.Value = message;
Response.Cookies.Add(myCookie);
It is giving NullReferenceException at the Response line. What could be the reason?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Either the
Cookiesproperty or theResponseobject is null. This could happen depending on where you are calling this code. For example if you attempt to access theResponseobject in a background thread it might be null because there’s no HttpContext associated to background threads.