Reputation: 1161
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?
Upvotes: 0
Views: 738
Reputation: 1038710
Either the Cookies
property or the Response
object is null. This could happen depending on where you are calling this code. For example if you attempt to access the Response
object in a background thread it might be null because there's no HttpContext associated to background threads.
Upvotes: 2