Use cookies to store the session ID at the same time it's assigned to the user the regular way. If at some point the cookie ID doesn't match the web page ID, revert to the cookie ID. If the cookie ID is lost, revert to the web page ID. I'd personally also store the IP address for those times when both IDs are lost.
You might also be interested in the following:
http://www.htmlgoodies.com/tutors/refresh.html