如何在asp.net中关闭浏览器时执行自动注销 [英] How to perform Auto Sign out on close of Browser in asp.net
本文介绍了如何在asp.net中关闭浏览器时执行自动注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在ASP.NET中关闭浏览器时执行自动注销?
How to perform Auto Sign out on close of Browser in ASP.NET?
推荐答案
在我的ASP.NET MVC网站的主要布局(母版页)中我正在使用下一个java脚本:
In my main layout (master page) of my ASP.NET MVC site I am ussing the next java script:
<script>
function onWindowClosing() {
if (window.event.clientX < 0 || window.event.clientY < 0)
{
.ajax( {
类型: POST,
url: / Account / OnWindowClosing
});
}
};
函数onKeydown(evt){
如果(evt!= undefined&& evt.altKey&& evt .keyCode == 115 ) // Alt + F4
{
.ajax({ type: "POST", url: "/Account/OnWindowClosing" }); } }; function onKeydown(evt){ if (evt != undefined && evt.altKey && evt.keyCode==115) //Alt + F4 {
.ajax({
type: POST,
url: / Account / OnWindowClosing
});
}
};
window.onbeforeunload = onWindowClosing;
window.document.onkeydown = onKeydown;
< / script >
.ajax({ type: "POST", url: "/Account/OnWindowClosing" }); } }; window.onbeforeunload = onWindowClosing; window.document.onkeydown = onKeydown; </script>
您应该在母版页中执行类似操作。
然后在您的源代码中(OnWindowClosing操作来自我的例子中的帐户控制器)你可以做你想做的事。
You should do something similar in your master page.
Then in your source code ("OnWindowClosing" action from "Account" controller in my example) you could do what you want.
这篇关于如何在asp.net中关闭浏览器时执行自动注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文