自动注销 [英] Log off automatically

查看:76
本文介绍了自动注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个登录表单和更多表格。我需要在用户刷新或按后退按钮时自动注销或关闭浏览器如何执行此操作?在此先感谢。

Hi all,
I have a login form and some more forms for the process. I need to log off automatically when the user refresh or press back button or closes the browser how to perform this? Thanks in advance.

推荐答案

您好


我是您使用ASP.NET平台的气体,因此您可以使用超时标签来自身份验证元素代码示例:



Hi
I gases you are in ASP.NET plat form so you can use timeout tag from authentication element follow of code demonstrate :

<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" timeout="3000">
</forms>
</authentication>





所以也许你的应用程序托管在IIS中不要担心我们有其他解决方案,请按照以下步骤操作:



1)请在运行中使用此命令inetmgr打开您的IIS

2)展开默认网站并右键单击您的网站/ Proerties

3)在网站属性对话框中,转到ASP.Net选项卡,单击编辑配置按钮

4)在ASP.Net配置设置对话框中,转到状态管理选项卡并增加会话超时(分钟)



of cour你应该使用 FormsAuthentication.SignOut 你可以在这里获得更多相关信息:http://msdn.microsoft.com/en-us/library/system.web.security .formsauthentication.signout.aspx?cs-save-lang = 1& cs-lang = csharp#code-snippet-2。





So maybe your application is hosted in IIS don`t worry we have a other solution for it please follow these steps:

1) Please open your IIS with this command "inetmgr" in run
2) Expand Default Web site and Right Click on your Web Site/Proerties
3) In the Web Site Properties dialog box go to ASP.Net tab click on Edit Configuration button
4) In the ASP.Net Configuration Setting dialog box go to State Management Tab and Increase the Session timeout (minutes)

Of course you should use FormsAuthentication.SignOut you can get more information about it here: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2.

public void Login_OnClick(object sender, EventArgs args)
{
  FormsAuthentication.SignOut();
  FormsAuthentication.RedirectToLoginPage();
}





因此,当用户刷新页面时,您可以使用这些方法退出;)

最好的问候。



So you can use these method for sign out when the user refresh the page ;)
Best Regards.


它的床位理念。如果页面没有正确加载并且用户想要返回或刷新页面,该怎么办?浏览此链接描述了这个。您可以使用这个链接
Its bed idea.What if the page is not properly loaded and user wants to go back or refresh the page? Go through this link which describes this.You can further implement it using this link


这些方式不可靠。当您按后退按钮时,您将从缓存中获取一个页面,因此您的服务器端不会收到HTTP请求。此外,当您关闭浏览器窗口时,没有任何反应;但是,这种情况更容易:你可以在JavaScript中处理这个事件。



即使你无法处理单击返回导航操作,你也可以禁用按钮是某些情况。请参阅此CodeProject文章:退出后浏览器返回按钮问题 [< a href =http://www.codeproject.com/Tips/135121/Browser-back-button-issue-after-logouttarget =_ blanktitle =New Window> ^ ]。



现在,关于捕获用户关闭浏览器窗口时的情况。



您可以处理事件JavaScript中的 onunload

http:/ /www.w3schools.com/jsref/event_onunload.asp [ ^ ]。



在处理程序中,您可以使用Ajax发送注销的HTTP请求。



-SA
These ways won''t be really reliable. When you press the back button, you get a page from cache, so your server side does not get an HTTP request. Also, when you just close the browser window, nothing happens; however, this case is easier: you can handle this event in JavaScript.

Even though you cannot handle a click the "Back" navigation operation, you can instead disable back button is certain cases. Please see this CodeProject article: Browser back button issue after logout[^].

Now, about capturing the even when a user closes a browser window.

You can handle the events onunload in JavaScript:
http://www.w3schools.com/jsref/event_onunload.asp[^].

In the handler, you can use Ajax to send an HTTP request for log off.

—SA


这篇关于自动注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆