0
我很困惑,我有下面的類定義不能在Page_Load中訪問公共類枚舉ASP.NET
public class User
{
public enum UserRoleTypes : int
{
Guest = 0,
User = 1,
Administrator = 2,
Developer = 3,
}
}
但是試圖在像這樣的Page_Load方法來訪問這個公共枚舉時。
public partial class Options_AccessControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
User currentUser = OCMSession.getCurrentUser(this);
if (currentUser.getRoleID() < (int)User.UserRoleTypes.Administrator)
{
LogWriter logger = new LogWriter();
}
}
}
我收到以下錯誤消息。
Error 5 'System.Security.Principal.IPrincipal' does not contain a definition for 'UserRoleTypes' and no extension method 'UserRoleTypes' accepting a first argument of type 'System.Security.Principal.IPrincipal' could be found (are you missing a using directive or an assembly reference?) H:\SVN\OCM\Options\AccessControl.aspx.cs 15 49 OCM
但是,相同的代碼在沒有User類定義的情況下工作。與Entity.UserRoleTypes類似,或者如果我將該枚舉定義移到該類之外。任何幫助理解這個錯誤是不勝感激。
有沒有一種方法來指定頁面屬性上的類?也許把它放到一個名字空間裏。 – garyamorris
@garyamorris,是的,只需使用命名空間指定更具體的路徑...在我看來,這很醜陋,但它起作用。 – walther