asp.net扩展IPrincipal

twa*_*wal 8 c# inheritance interface iprincipal

我想在asp.net中扩展IPrincipal以允许我获得我将定义的usertype.我想在控制器中做到这一点

string type = User.UserType 
Run Code Online (Sandbox Code Playgroud)

然后在我的扩展方法中,我将有一个方法,如

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

}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?可能吗?谢谢!

SLa*_*aks 11

您可以制作扩展方法:

public static string UserType(this IPrincipal principal) {
    // do some database access 
    return something;
}
Run Code Online (Sandbox Code Playgroud)