1

MVC5 controllers have a User property which is a System.Security.Claims.ClaimsPrincipal

I've created a base controller which I inherit from. This base controller's User property is overridden with mycustomPrinciple which inherits from System.Security.Claims.ClaimsPrincipal

 public abstract partial class BaseController : Controller
    {

        public new mycustomPrinciple User
        {
            get
            {
                return base.User as mycustomPrinciple;  //returns null here
            }
        }
     }

public class mycustomPrinciple : System.Security.Claims.ClaimsPrincipal
    {
        private int _ID;

        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

    }

as you can see above it fails on the cast. I'm unsure as to why this is as i did a similar thing in MVC4 but the inherited principle was System.Security.Principal.IPrincipal as this is what the controllers User property was a type of.

Tim
  • 7,401
  • 13
  • 61
  • 102

1 Answers1

0

You're missing the point of ClaimsPrincipal -- the Claims collection is where you'd keep your app-specific identity data. Then I'd suggest adding extension methods to extract the specific claims like your "ID".

Brock Allen
  • 7,385
  • 19
  • 24
  • so once someone logins in using one of the methods, you add a claim to the collection with an id to allow you to identify the user in your database for example, and provide an extention method to the claimsprinciple class so you can pull this out, or the database userrecord? – Tim Jul 15 '13 at 13:59
  • Yes. You'd do this in the WIF extensibility point called a "claims authentication manager" (we prefer to call it a claims transformer). – Brock Allen Jul 19 '13 at 03:51
  • I'm confused between this and some of the answers for a similar query in http://stackoverflow.com/questions/17641956/howto-use-new-mvc5-authentication-with-existing-database. I guess more detail will come out when it RTM's but there is scant detail about the customisation of the new claims/identity system in MVC5 – Tim Jul 22 '13 at 06:20