0

I am using cookie and I am setting its value like this,

document.cookie = 'province=Alberta; expires=Fri, 3 Dec 2014 20:47:11 UTC; path=/'

And I am trying to read it on my server side like following

if (Response.Cookies["province"].Value != null)

But the Response.Cookies["province"].Value is giving me null.

What may the reason for this?

1
  • 1
    Surprising that search engine you are using did not give any links. Consider Bing - C# read cookie. (I work for Microsoft, so mentioning Bing, C# and MSDN could be considered advertisement, in this case use Google link - to search google.com/search?q=c%23+read+cookie ) Commented Oct 6, 2014 at 16:48

1 Answer 1

5

You need to look in the request, not the response. The request is what is sent to the server. The response is what you send to the client. For example:

string cookieValue = string.Empty;

if (Request.Cookies["province"] != null)
{
    cookieValue = Request.Cookies["province"].Value.ToString();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.