这里是我的做法。创建一个新的BasePage
并继承您的aspx页面而不是System.Web.UI.Page。
public class BasePage : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
if (!IsPostBack)
{
// I assume you already get the user's profile
if (User.IsSuspended)
Response.Redirect("/SuspendedPage.aspx");
base.OnInit(e);
}
}
}
更新时间:
有很多的方法,通过存储的值进行应用程序生命周期。这是其中之一。
// Global.asax.cs
void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (HttpContext.Current.User != null &&
HttpContext.Current.User.Identity.IsAuthenticated)
{
HttpContext.Current.Items["User"] =
GetUserByUsername(HttpContext.Current.User.Identity.Name);
}
}
来源
2012-12-21 18:50:46
Win
对asp.net一点都不熟悉,所以我不知道这个建议是否适用,但我只是在用户挂起时清除所有活动会话数据。这将有效地登出他们的下一页加载。 –
我只会在每次回发中检查数据库。我认为与回发时间相比,低效率可以忽略不计。 –
如果您想对每个请求执行检查,则HTTP模块可能是最简单的选项:http://support.microsoft.com/kb/307996 –