asp.net extending IPrincipal

twal picture twal · Jul 9, 2010 · Viewed 8.2k times · Source

I would like to extend IPrincipal in asp.net to allow me to get the usertype that I will define. I would like to make it possible to do this in a controller

string type = User.UserType 

then in my extension method i will have a method like

public string UserType()
{
  // do some database access 
  return userType

}

how can I do this? is it possible? Thanks!

Answer

SLaks picture SLaks · Jul 9, 2010

You can make an extension method:

public static string UserType(this IPrincipal principal) {
    // do some database access 
    return something;
}