我已经设置了一个asp.net登录控件(从asp.net配置提供的控件),它工作正常。Asp.net登录控制Autologout/AutoRedirect和标签值
我已将代码添加到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>
如果使用该代码,那么我会得到autologout,如果在3分钟后点击链接,然后进入登录页面。
这是如何工作的?是登录3分钟还是3分钟不活动!
另外,我可以在我的登录页面添加一个标签,然后它会告诉用户他/她为什么重定向到登录页面,如果是的话,怎么样?
最后:我怎样才能在3分钟后将用户重定向到登录页面。所以它不是3分钟后。然后当用户点击一个链接,但在3分钟后,刷新(如果不活动),然后自动跳转到登录页面并用文本显示我的标签,说明他/她没有登录的原因!
.............................................. .................................................. .................................................. ..........................
我无法得到它的工作,如果我们看看没有。 2解决方案。我有这个在page_load会话(“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
plz。请参阅主要问题中的附加代码。 –