ManxJason
ManxJason

Reputation: 940

Create cookie in C# and change the value via Javascript

Is it possible to access a C# created cookie via Javascript and change the value? (I'm aware that it's a security measure - but whats the alternative)

C#

 HttpCookie myCookie = new HttpCookie("theName", "theValue");
 Response.Cookies.Add(myCookie);

Javascript

console.log(document.cookie) //doesn't include my cookie..

Upvotes: 0

Views: 926

Answers (1)

ManxJason
ManxJason

Reputation: 940

HttpCookie is by default protected - i.e. Javascript cannot read them. Setting the following bool property allows access.

myCookie.HttpOnly = false

Upvotes: 1

Related Questions