Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 30, 2012 07:36 AM by Ruchira
Member
61 Points
72 Posts
May 29, 2012 12:18 PM|LINK
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?
Response Cookie csharp
Star
9250 Points
1578 Posts
May 29, 2012 12:21 PM|LINK
There are examples of how to write cookies here
http://msdn.microsoft.com/en-us/library/ms178194.aspx
All-Star
16460 Points
3178 Posts
May 29, 2012 12:23 PM|LINK
Are you getting an exception or a warning?
May 29, 2012 12:27 PM|LINK
nijhawan.saurabh Are you getting an exception or a warning?
I am getting an Exception in the catch block.
May 29, 2012 12:34 PM|LINK
Ok. Are you doing this in aspx.cs page or some other class?
HttpContext.Current could be Null if there is no Web Request.
44362 Points
7194 Posts
MVP
May 30, 2012 07:36 AM|LINK
Hello,
praptic Response.Cookies.Add(myCookie); It is giving NullReferenceException at the Response line. What could be the reason?
Response.Cookies.Add(myCookie);
Try by modifing it as below
HttpContext.Current.Response.Cookies.Add(myCookie);
Also, where are you setting this cookie?
Please 'Mark as Answer' if this post helps you.
praptic
Member
61 Points
72 Posts
NullReferenceException in Cookies
May 29, 2012 12:18 PM|LINK
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?
Response Cookie csharp
AidyF
Star
9250 Points
1578 Posts
Re: NullReferenceException in Cookies
May 29, 2012 12:21 PM|LINK
There are examples of how to write cookies here
http://msdn.microsoft.com/en-us/library/ms178194.aspx
Response Cookie csharp
nijhawan.sau...
All-Star
16460 Points
3178 Posts
Re: NullReferenceException in Cookies
May 29, 2012 12:23 PM|LINK
Are you getting an exception or a warning?
praptic
Member
61 Points
72 Posts
Re: NullReferenceException in Cookies
May 29, 2012 12:27 PM|LINK
I am getting an Exception in the catch block.
nijhawan.sau...
All-Star
16460 Points
3178 Posts
Re: NullReferenceException in Cookies
May 29, 2012 12:34 PM|LINK
Ok. Are you doing this in aspx.cs page or some other class?
HttpContext.Current could be Null if there is no Web Request.
Ruchira
All-Star
44362 Points
7194 Posts
MVP
Re: NullReferenceException in Cookies
May 30, 2012 07:36 AM|LINK
Hello,
Try by modifing it as below
Also, where are you setting this cookie?
Response Cookie csharp
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.