检测时,用户会话具有EXI preD用户、EXI、preD

2023-09-04 12:17:30 作者:孤街浪徒

谁能告诉我如何检测,当用户会话具有EXI preD在ASP?

Can anyone tell me how to detect when a users session has exipred in asp?

我想将用户重定向到一个注销页面,一旦会话已过期

I want to redirect users to a logged out page once the session has expired

谢谢 SP

推荐答案

使用的Session_End中()函数在Global.asax文件。请在这里看到更多的信息。

Use the Session_End() function in your global.asax file. Please see here for more info

SO - 会话结束

编辑:没有,这可能会那么做。请参见下面的评论。

Nope, that probably won't do it. See comments below.

如果您必须重定向会话过期的,将是这样做的伎俩吗?

If you must redirect on a session expiration, would something like this do the trick for you?

private void Page_Load(object sender, System.EventArgs e)
{ 

Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 60) + 5)); 
if(Session["IsUserValid"].ToString()=="") 
Server.Transfer("Relogin.aspx");

}

编辑2:警告,如果你有AJAX的东西怎么回事这个可能很麻烦

EDIT 2: Caveat, this can get tricky if you have AJAX stuff going on.

我看到的例子,人们就会把这个基页在Page_Load和inheirit都来自这个基地页您的.aspx页面。这prevents您不必添加此$ C $下,你必须每一个页面。

I have seen examples where people will put this in the page_load of a base page and inheirit all of your .aspx pages from this base page. This prevents you from having to add this code for every single page that you have.

为什么不第一种方法的工作(Session_End中)?这是一个内部调用服务器上,当会议结束的功能。因此,不存在相关联请求/响应重定向或传输。也就是说,该功能可以通过服务器来叫你关闭browswer 20分钟后。

Why won't the first method work (Session_End)? This is a function called internally on the server when a session ends. As such, there is no associated request/response to redirect or transfer. I.e., this function could be called by the server 20 minutes after you close the browswer.