Tuesday, 8 November 2011

Log off when you close the browser

 /*in master page Javascript*/

        $(document).ready(function() {
            debugger;
            var hdf = $('#ctl00_hdflog').val();
            if (hdf == '1') {
                $('body').attr("onunload", "javascript:removesessions();");
            }
        });

        function removesessions() {
            $.ajax({
                url: window.location.href + (window.location.href.toString().indexOf('?') > -1 ? '&close=force' : '?close=force'),
                async: false
            });
        }

/*You need a hidden field */
<input type="hidden" runat="server" id="hdflog" value="0" />
  
  /*Cs file on page load*/
            if (Request.QueryString["close"] != null && Request.QueryString["close"] == "force")
            {
                FormsAuthentication.SignOut();
                Session.Abandon();
                Session.Clear();
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Cache.SetAllowResponseInBrowserHistory(false);
            }

No comments:

Post a Comment