Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,I am storing some data in session in codebind as
C#
protected void Page_Load(object sender, EventArgs e)
   {
       Session["kkk"]="kkk";
   }


and trying to read this session cookie id in javascript as
<a href="#"  önclick="myname()">
   read cookie here
   </a>

 <script> function myname() {
    alert(document.cookie);

} </script>


But its returning empty cookie ??
Please help
Posted

1 solution

This is by design.

The session cookie is just a random identifier which the server uses to map the request to a particular session object. As such, it isn't meant to be read from the client, so the cookie has the HttpOnly flag set. This is a good thing, because it prevents malicious script from hijacking your session.

Even if you could read the session cookie, it's just a meaningless ID. Values stored within the session will not be available from your script.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900