There is a bit of an uncertainty principle in trying to detect when a session has expired. By querying the server to see if it is alive (using AJAX or similar), you are actually keeping it alive, which is usually the exact opposite behavior that you want.
I usually do this by embedding javascript code in the page. :
var sessionTimeout = 20; //minutes - set this programmatically server-side based on your configured timout interval
setTimeout('timeoutAlert()', (sessionTimeout + 1) * 1000 * 60); //we add one minute buffer because this is an inaccurate process and we want to make sure they are actually timed out before we attempt to redirect
function timeoutAlert()
{
alert("Your sesssion has ended, you will now be redirect to the login page.");
document.location = '/home.aspx';
}
Note this timeoutAlert() can modify some HTML client-side, run some AJAX to execute code server-side, whatever you need it to do. You will have to be careful to cancel and reset the setTimeout if you make any calls to the server (e.g., via AJAX) after the page is rendered.