I wanted to remove the user session and related data when the user closes the browser. i referred to this (<http://weblogs.asp.net/kaushal/archive/2011/02/25/user-is-trying-to-leave-trap-and-set-confirm-alert-on-browser-tab-close-event.aspx>) post and i have some coding as below. I wanted to delete the user data from the application state and SQL server database when the user closes the browser. And i am doing this with the help of a handler.
The below code is working fine while debugging, it is calling the handler and executing all the codes which i have written in to it. But when i really use this app this is not working. I don't know where the problem is. And it is eating my time. 
(I am using this inside the content of a Master page)

```
window.onbeforeunload = confirmExit;
function confirmExit() {

    var UserID = '<%= Session["UserID"] %>';

        $.ajax({
            type: "POST",
            url: "../../Handlers/HandlerUser.ashx?Action=RemoveUserDataOnBrowserClose&UserID=" + UserID.toString(),
            contentType: "application/json; charset=utf-8",
            async: false,
            success: function (data) {

            }
        });

}

```

if any one can suggest another way to achieve the same, it will be a great help.