I have a scenario where I open my web application in a browser but in two separate tabs.
In one tab I signed out from the application and as a result the all session values becomes null. While in the other tab I clicked on an anchor tag in the webapplication. In the anchor tag's jquery-on click event I have checked the session value. Here I am supposed to get the session as null(since I logged out the application from the other tab), but I am getting session value as logged in user(probably because no page refresh occurs).
My idea is to check the session on jQuery and if the session is null make the application logout,otherwise show a popup page..
Here's my code for getting the session value
$(".a".click(function(){ var session=var data = '@Session["UserName"]'; if(session!=null){ //Show popup } else{ //Show loginpage } }))
How can I get the current session value in jQuery?
You can't access Session directly in JavaScript.
String a = Login1. UserName; Session["user"] = a; Response. Redirect("~/Home. aspx");
Introduction to JavaScript sessionStorageThe sessionStorage object stores data only for a session. It means that the data stored in the sessionStorage will be deleted when the browser is closed. A page session lasts as long as the web browser is open and survives over the page refresh.
The session is a server side thing, you cannot access it using jQuery. You can write an Http handler (that will share the sessionid if any) and return the value from there using $.ajax
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With