开发者

How to check/assign user's roles right after signing in?

For my application when the user logs in I need to check if they have any roles assigned to them and if they don't assign them a basic ro开发者_如何学Cle. Also based on their role I have to redirect them to certain pages. But I can't find a way to check/set user's roles when they sign in.

    [HttpPost]
    public ActionResult LogOn(LogOnModel model, string returnUrl)
    {
        if (ModelState.IsValid)
              {
               if (MembershipService.ValidateUser(model.UserName, model.Password))
                 {
                      FormsService.SignIn(model.UserName, model.RememberMe);
                     if(User.IsInRole("User")) 
//This won't work becauser User is not populated yet. It will be populated only on next request for some reason that has to do with setting cookies
    }

Any ideas how to work this out?


Some thing like this?

if(User.IsInRole(model.UserName, "User")) 


Apparently Roles.IsUserInRole method allows to pass string as username, so it makes possible to check users membership without calling the User object.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜