I’m using ASP.NET MVC 3 with Entity Framework 4. When a user logs in, i would like to store some informations from the database like ID, Name etc. So i created my own CustomIdentity/CustomPrincipial but i dont want to cast every time, so i create a BaseController who cast the Identity:
public class BaseController : Controller
{
public CustomIdentity CustomIdentity { get { return (CustomIdentity)User.Identity; } }
}
and all my other Controllers interhit from the BaseController. But i dont think this is a good practise. Is there a better way?
I would use an extension method to avoid additional inheritance
this is a little more discoverable and there isn’t confusion about whether User.Identity or CustomerIdentity should be used. when you need the identity
and when you need the additional property