简体   繁体   中英

Calling C# sessions using jQuery

I have created a session using .net and c#. I am trying to call that session on jquery using the code below:

$( document ).ready(function() {
    console.log( '<%=Session["CoBrowse"].ToString() %>' );
});

However, the console treats it as a string and not ac# code. Hence the output is:

'<%=Session["CoBrowse"].ToString() %>'

and not the session code.

JavaScript runs at Client Side and sessions are maintained at Server side. So these two things can not work side by side. However you can do something like this

    <script runat="Server">
  $( document ).ready(function() {
console.log( '<%=Session["CoBrowse"].ToString() %>' );
  });

 </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM