我已经设置了一个 asp.net 登录控件(由 asp.net 配置提供的控件),它工作正常。
我已将代码添加到 web.config,因此 3 分钟后,它会自动注销用户。
<authentication mode="Forms">
<!-- Autologout after xxx min. to login.aspx -->
<forms loginUrl="~/login.aspx" defaultUrl="~/login.aspx" slidingExpiration="true" timeout="3"/>
</authentication>
如果使用该代码,则我会自动注销,如果在 3 分钟后单击链接,则我会进入登录页面。
这是如何运作的?是在登录后 3 分钟还是在 3 分钟不活动后!?
另外,我可以在我的登录页面上添加一个标签,然后它会告诉用户为什么他/她被重定向到登录页面,如果是的话如何?
最后:如何让它在 3 分钟后将用户重定向到登录页面。所以不是在3分钟之后。然后当用户点击一个链接时,但在 3 分钟后,刷新(如果不活动)然后自动跳转到登录页面并用文本显示我的标签,解释为什么他/她没有登录!??
..................................................... ..................................................... ..................................................... ……………………………………………………………………………………………………………………
如果我们查看否,我无法让它工作。2 解决方案。
在我的主页(code_behind)上,我在 page_load Session("logintime") = DateTime.Now.ToString() 中有这个响应写入我在主页 01-10-2012 18:30:42 上得到这个,现在是 18 :37:25 它还没有重定向,我根本没有在浏览器窗口中进行活动。
我的主页代码是。
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="default.aspx.vb" Inherits="_default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var count = 30000
var timeLoggedIn = new Date('<%=Session("logintime")%>')
var timeLogOut = new Date('<%=Session("logoutTime") %>');
setTimeout(LoggedInCheck(), 30000);
function LoggedInCheck() {
var now = new Date();
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
if (now_utc > timeLogOut) {
window.location = "http://www.google.dk";
}
}
function countDown() {
if (count <= 0) {
// window.location = redirect;
} else {
count--;
document.getElementById("timer").innerHTML = "This page will redirect in " + count + " seconds."
setTimeout("countDown()", 1000)
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<span id="timer">
<script>
countDown();
</script>
</span>
</div>
</form>
</body>
</html>
Code_behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Session("logintime") = DateTime.Now.ToUniversalTime().ToString("MM/dd/yyyy hh:mm:ss")
Session("logoutTime") = DateTime.Now.ToUniversalTime().AddMinutes(3).ToString("MM/dd/yyyy hh:mm:ss")
Response.Write("time now: " & Session("logintime"))
Response.Write("<br />")
Response.Write("reload at time: " & Session("logoutTime"))
End If
End Sub