开发者

Logout banned users

im banning users using the following:

MembershipUser user = Membership.GetUser(username);
if (user != null)
{
    user.IsApproved = false;
    user.LastLoginDate = DateTime.Now;
    Membership.UpdateUser(user);
}

if the user is currently logged in they can still do things on the site, so how can i also log th开发者_运维百科em off?


On your global.asax you can do something like this..

Application_OnAuthenticateReuqest(object sender, EventArgs e)
{
  if(!UserHasAccess())
  {
     FormsAuthentication.SignOut();
  }
}

private bool UserHasAccess()
{
   var user = Membership.GetUser(Context.User.Identity);

   return user.isApproved;
}

You may want to consider some form of caching...

And btw I am assuming you're using proper [Authorize] attributes on your controller methods.


You want to check on pageLoad of every request the users' status. If they are banned you can simply response.End() or response.Redirect() them to the home page.


You will have to validate whether the user has been banned on every request. You could achieve this using the HttpApplication (Global.asax) or preferably using a custom HttpModule.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜