Skip to main content

Clear Session on browser/tab close using JQuery

Add below script to master page and replace Logon with your login page.
<script type="text/javascript">
var LoginPageName = "Logon";
var AttachClearSessionEvent = true; var IsFormSubmit = false;
$(window).submit(function () { AttachClearSessionEvent = false; IsFormSubmit = true; window.onbeforeunload = null; });
$(document).ready(function () {var myEvent = window.attachEvent || window.addEventListener;var chkevent = window.attachEvent ?
'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable
myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefox
try {if (AttachClearSessionEvent) {var caller = '(document).ready';var urlToDisposeSession = LoginPageName;
$.ajax({cache: false,type: "POST",url: urlToDisposeSession,data: JSON.stringify({ RandomString: caller }),contentType:
"application/json; charset=utf-8",dataType: "json",async: false,success: function (msg) {}});}
}catch (ex) { }
});});
$(window).on('mouseover', (function () {AttachClearSessionEvent = false;window.onbeforeunload = null;}));
function addEvent(obj, evt, fn) {if (obj.addEventListener) {obj.addEventListener(evt, fn, false);}else if (obj.attachEvent)
{obj.attachEvent("on" + evt, fn);}}
addEvent(window, "load", function (e) {
addEvent(document, "mouseout", function (e) {e = e ? e : window.event;var from = e.relatedTarget || e.toElement;
if (!from || from.nodeName == "HTML") {
var callOnMouseOut = true;
if (IsFormSubmit) { callOnMouseOut = false; } if (callOnMouseOut) { AttachClearSessionEvent = false; window.onbeforeunload =
ConfirmLeavemouseout;}}
});});
function ConfirmLeave() {
try {var Caller = 'Keyboard';var urlToDisposeSession = LoginPageName;
$.ajax({cache: false,type: "POST",url: urlToDisposeSession,data: JSON.stringify({ RandomString: Caller }),contentType:
"application/json; charset=utf-8",dataType: "json",async: false});
}catch (ex) { }}
function ConfirmLeavemouseout() {
try {var Caller = 'mouseout';var urlToDisposeSession = LoginPageName;
$.ajax({cache: false,type: "POST",url: urlToDisposeSession,data: JSON.stringify({ RandomString: Caller }),contentType:
"application/json; charset=utf-8",dataType: "json",async: false,success: function(msg) {}});
}catch (ex) { }}
var prevKey = "";
$(document).keydown(function (e) {if (e.key == "F5") {window.onbeforeunload = ConfirmLeave;}else if (e.key.toUpperCase() == "W"
&& prevKey == "CONTROL") {window.onbeforeunload = ConfirmLeave;}
else if (e.key.toUpperCase() == "R" && prevKey == "CONTROL") {window.onbeforeunload = ConfirmLeave;}else if
(e.key.toUpperCase() == "F4" && (prevKey == "ALT" || prevKey == "CONTROL")) {window.onbeforeunload = ConfirmLeave;}
prevKey = e.key.toUpperCase(); });
</script>

Comments

Popular posts from this blog

Password Protected File Validation for(.doc/.docx/.xls/.xlsx/.pdf) file types

Password Protected File Validation for(.doc/.docx/.xls/.xlsx/.pdf) file types protected void btnUpload_Click( object sender, EventArgs e)         {             //Check if File Upload control has file or not             if (FileUpload1.HasFile)             {                 //Get Uploaded file bytes                 var bytes = FileUpload1.FileBytes;                 //Get Uploaded File Extension                 FileInfo objFileInfo = new FileInfo (FileUpload1.FileName);                 string StrFileExt = objFileInfo.Extension.ToUpper();                                 //Based on the File extension call appropriate user defined method.                 //For PDF file type                 if (StrFileExt == ".PDF" )                 {                     //Upload and save file in server temp folder                     var newfilename = DateTime .Now.GetHashCode() + FileUpload1.FileName;                     FileUpload1.SaveAs(Syst

Product/Application/ Software Security Testing

Product/Application/ Software Security Testing Application Security testing is the process to find security issues or security vulnerability in the application using automated and manual security scanner tools and share the identified issues or risk with development or application team. Process will remain mostly same in all the different types of application security scan. Before initiating security scan, its always good to identify the boundary and scope of your security testing.  Below are the few example of which we can consider as Application or software. ( Scope for Application Security Testing) Web Application, Portal. Web API. Desktop Software / Thick Client. Mobile Application. Web Services.  Plug in, Add-On The goal of application security is to secure the application and prevent the unwanted damaged. The process of performing security scan or audit is know as ASA (Application Security Assessment). Generally there are three types of ASA, SAST, DAST and PT. 

Improve SQL Server database design and performance

Improve SQL Server database design and performance http://www.dotnet-tricks.com/Tutorial/sqlserver/bM6H260812-Tips-to-improve-SQL-Server-performance.html