Javascript can access the cookie values, not the session object. But if your application needs session data to be shared to client side script, you can expose it to the page..using hidden fields or javascript variables..
The real voyage of discovery consists not in making new landscapes, but in having new eyes
Can we access value of cookies and session object using java script ?
Cookies: yes. Cookies are being transferred to the browser where you execute your javascript. As such these can be manipulated in the browser by javascript
Session: no. Session state is meant to be kept on the server and usually holds information you don't want to expose to the browser.
If you want to read out session state then you first need to make the decision as to why you want to do so. Session state is meant to be kept on the server for a reason. If you're sure you can/want to expose that information then don't use session state
but simply display (or in a hidden way) in the html that you send to the browser. If you do want to manipulate them but don't want to expose them provide an endpoint like Web API or WCF that you call via ajax to manipulate it on the server.
Member
218 Points
195 Posts
Acessing values from cookies and Session
Dec 20, 2014 04:02 AM|SURYA_TECH|LINK
Can we access value of cookies and session object using java script ?
If yes then explain me how ?
"Asp.Net Community Support"
All-Star
21303 Points
4516 Posts
Re: Acessing values from cookies and Session
Dec 20, 2014 05:12 AM|sreejukg|LINK
Javascript can access the cookie values, not the session object. But if your application needs session data to be shared to client side script, you can expose it to the page..using hidden fields or javascript variables..
My Blog
All-Star
191752 Points
20952 Posts
ASPInsiders
Moderator
MVP
Re: Acessing values from cookies and Session
Dec 20, 2014 05:24 AM|XIII|LINK
Hi,
If you want to read out session state then you first need to make the decision as to why you want to do so. Session state is meant to be kept on the server for a reason. If you're sure you can/want to expose that information then don't use session state but simply display (or in a hidden way) in the html that you send to the browser. If you do want to manipulate them but don't want to expose them provide an endpoint like Web API or WCF that you call via ajax to manipulate it on the server.
For the cookies part with examples read this article: http://www.quirksmode.org/js/cookies.html.
Grz, Kris.
Working with Azure, chatbots, ASP.NET MVC, Web API, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!