This project is read-only.

HOW DO USE THIS IN AN ASP.NET MVC PROJECT?

 

 public class BaseController : Controller 
    {
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (User != null)
            {
                if (User.Identity.IsAuthenticated)
                {
                    IIdentity identity = base.User.Identity;

                    CustomClaimsPrincipal claimsPrincipal = (CustomClaimsPrincipal)filterContext.HttpContext.Cache.Get(identity.Name);
                    if (claimsPrincipal == null)
                    {
                        int universalId = GetUniversalUserId(identity.Name);

                        // Create and populate your Principal object with the needed data and Roles. 
                        CustomPrincipal genericPrincipal = new CustomPrincipal(base.User.Identity, Roles.GetRolesForUser(identity.Name), GetUniversalUserId(identity.Name));

                        claimsPrincipal = GetClaimsPrincipalByIdentity(genericPrincipal);
                        claimsPrincipal.UniversalUserId = universalId;

                        filterContext.HttpContext.Cache.Add(
                        identity.Name,
                        claimsPrincipal,
                        null,
                        System.Web.Caching.Cache.NoAbsoluteExpiration,
                        new System.TimeSpan(0, 30, 0),
                        System.Web.Caching.CacheItemPriority.Default,
                        null);
                    }
                    filterContext.HttpContext.User = claimsPrincipal;
                    System.Threading.Thread.CurrentPrincipal = claimsPrincipal;
                    base.OnAuthorization(filterContext);
                }
            }
        }

//... other methods
}

Last edited Jan 16, 2013 at 3:09 PM by shanthuk, version 1

Comments

No comments yet.