Reputation: 3401
I have used cookie to store the value and while adding data to cookie I have secure it using cookie.secure but when I am trying to get the cookie value using Request.Cookies["Key"].Value it throws an exception because Request.Cookies["Key"] is null.If I remove cookie.secure it's working fine.So please help me how to read secure cookie value.Following code I have used to store and secure cookie.
HttpCookie strcookie = new HttpCookie("Key");
strcookie.Value = "XYZ";
strcookie.HttpOnly = true;
strcookie.secure=true;
HttpContext.Current.Response.Cookies.Add(strcookie);
Upvotes: 1
Views: 2139
Reputation: 18127
Secure cookie
A secure cookie can only be transmitted over an encrypted connection (i.e. HTTPS). This makes the cookie less likely to be exposed to cookie theft via eavesdropping.
You can read it in Wikipedia there is whole point about it. I will suppose that you are not using HTTPS and because of that the value of the cookie is null. If you want to use secury cookie you should ensure that the pages are using HTTPS.
Upvotes: 5