我有一个 .Net 3.5 网站,它使用 Windows 身份验证并在我的基本母版页类的预呈现上使用元标记使 session 过期。
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (Response.ContentType == "text/html")
this.Page.Header.Controls.Add(new LiteralControl(
String.Format("<meta http-equiv='refresh' content='{0};url={1}'>",
SessionLengthMinutes * 60, SessionExpireDestinationUrl)));
}
这适用于进行完整回发的页面。但是,在我的应用程序中有几个页面,用户在更新面板内进行了大量工作。我公司的政策是超时 15 分钟。这意味着,在更新面板页面内部工作 15 分钟后,用户将被重定向到应用程序初始页面。
有没有办法重置或扩展异步回发中的元标记?或者也许有更好的方法来完全实现这一目标?
最佳答案
完全完成此任务的更好方法是使用 javascript。如果您的页面已添加书签,这将防止与元刷新相关的问题。
代替页面 META REFRESH 使用此 javascript:
<script type="text/javascript">
var _timerID = setTimeout("window.location='splash-url'", 900000); //15 mins
</script>
当您从更新面板发出请求时,请使用此 javascript:
<script type="text/javascript">
clearTimeout(_timerID);
_timerID = setTimeout("window.location='splash-url'", 900000); //15 mins
</script>
关于c# - 使用 AJAX 时如何防止 session 过期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3739676/