Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guys

I am currently busy on an application in MVC and have a search method on screen that calls the ActionResult in the backend code, all works well the issue i picked up is if the user leaves the page and the session times out and the user tries to search because the search doesnt do an actual postback it think it is not picking up the session has expired so the Javascript runs and shows the search animation to say it is searching but nothing is really happening on the page and the actionresult is never called cause the session has expired.

How could i get the Javascript to see if the user session created on login exists or not?

What I have tried:

i have tried something like the below but didnt seem to work
if ('<%=Session("UserSessionID")%>' == null)
{
window.location("login")
}
        {
Posted
Updated 25-Aug-17 0:35am

1 solution

You are mixing the two worlds here, and that is never going to end up well. Without any further complications, I would recommend that you bring these elements to the client-side and consider using JavaScript APIs such as sessionStorage to maintain this session. Now, since the session values are offline, it doesn't require a postback and updating the values because browser can be queried to check if the session exists or did it expire.

Window.sessionStorage - Web APIs | MDN[^]
 
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