Ejemplo n.º 1
0
 protected void AddToRole_Click(object sender, EventArgs e)
 {
     IsInRole.Text = AppSecurity.Create()
                     .IsInAppRole(User.Identity.Name,
                                  GivenRoleName.Text,
                                  true)
                   ? "Yes" : "No";
 }
Ejemplo n.º 2
0
        // Credits: https://brockallen.com/2012/05/23/think-twice-about-using-roleprovider/
        void Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            var ctx = HttpContext.Current;

            if (ctx.Request.IsAuthenticated)
            {
                string[] roles   = AppSecurity.Create().GetUserRoles(ctx.User.Identity.Name);
                var      newUser = new GenericPrincipal(ctx.User.Identity, roles);
                // Assign the updated user info to both
                // the current thread and the current HttpContext
                ctx.User = Thread.CurrentPrincipal = newUser;
            }
        }