How to assign value to a session using javascript

Working on Asp.Net C # VS08 I would like to assign a value to a session using javascript. Is it possible?

example: Session ["Id"] = document.getElementById ("id"). value;

+3
source share
4 answers

A session is a server concept; Javascript has no idea about this.

You can create an AJAX service that sets the session value.

However, most likely you should use a cookie. You can set cookies in Javascript using this library , among others.

+4
source

No, this cannot be done directly with JavaScript on the client side.

. , cookie, , . , , cookie- .

JavaScript XMLHttpRequest ASP.NET, , , . , , , .

+2

, , JavaScript. cookie.

http://www.w3schools.com/js/js_cookies.asp

, , Ajax.

+1
source

No, It is Immpossible. A session is a server object. A few ways to do this is to send cookies from JavaScript and use them on the server side to assign a value to the session variable or make an AJAX call and set the values ​​on the server.

0
source

Source: https://habr.com/ru/post/1729506/


All Articles