Skip to content

Instantly share code, notes, and snippets.

@b-tiwari
Created November 6, 2017 04:30
Show Gist options
  • Select an option

  • Save b-tiwari/892e8641ff84b19adfc257335317b63a to your computer and use it in GitHub Desktop.

Select an option

Save b-tiwari/892e8641ff84b19adfc257335317b63a to your computer and use it in GitHub Desktop.
AppUserPrincipalClaims.cs - Claims based identity in ASP.Net MVC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Web;
namespace csWinAuthWClaims.Views
{
    public class AppUserPrincipalClaims : ClaimsPrincipal
    {
        public AppUserPrincipalClaims(ClaimsPrincipal principal)
            : base(principal)
        {
        }
        public string GivenName
        {
            get { return this.FindFirst(ClaimTypes.GivenName).Value; }
        }
        public string Surname
        {
            get { return this.FindFirst(ClaimTypes.Surname).Value; }
        }
        public string Email
        {
            get { return this.FindFirst(ClaimTypes.Email).Value; }
        }
      
        public string WindowsAccountName
        {
            get { return this.FindFirst(ClaimTypes.WindowsAccountName).Value; }
        }
      
      
         public string myAppUserRole
        {
            get { return this.FindFirst("myAppUserRole").Value; }
        }
         public string MyCustomClaim
        {
            get { return this.FindFirst("MyCustomClaim").Value; }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment