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?
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?
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.