Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi All,
Its not Umbraco related question but this community is so frendly that i will ask here.
I want to save cookie every time visitor comes to my website and before I do that I want to check if cookie alredy exist.
I am doing this with this static method:
public bool IsReturningVisitor(string value) { if (Request.Cookies[value] != null) { return true; } else { Response.Cookies[value].Value = value; Response.Cookies[value].Expires = DateTime.Now.AddMinutes(1); return false; } }
But I am geting null reference on this line Request.Cookies[value] != null . When i do the same thing in my ActionResult class it works good.
Request.Cookies[value] != null
What am I missing??
Hi Silvija.
Are you sure you have a Request? If you do it in a static class with a static method you might not have the Request object available.
If you have a Request object, check to see what the Cookies property actually contains, maybe what you think your key is, is not what it actually is.
Regards Malthe
Hi Malthe,
Yes that is true, Request is null. I cant find solution how to solve it. Is there a way to get the cookies in that situation?
BR
Silvija
Hi again.
Yes. You can get the Request/Response object from HttpContext.Current.Request/Response.
Regards
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Request Cookies Null reference
Hi All,
Its not Umbraco related question but this community is so frendly that i will ask here.
I want to save cookie every time visitor comes to my website and before I do that I want to check if cookie alredy exist.
I am doing this with this static method:
But I am geting null reference on this line
Request.Cookies[value] != null
. When i do the same thing in my ActionResult class it works good.What am I missing??
Hi Silvija.
Are you sure you have a Request? If you do it in a static class with a static method you might not have the Request object available.
If you have a Request object, check to see what the Cookies property actually contains, maybe what you think your key is, is not what it actually is.
Regards Malthe
Hi Malthe,
Yes that is true, Request is null. I cant find solution how to solve it. Is there a way to get the cookies in that situation?
BR
Silvija
Hi again.
Yes. You can get the Request/Response object from HttpContext.Current.Request/Response.
Regards
is working on a reply...