【发布时间】:2015-04-23 10:53:40
【问题描述】:
我正在向IPrincipal 添加一个成员。我用@User.LastName
我收到一个错误:
CS1061:“System.Security.Principal.IPrincipal”不包含“LastName”的定义,并且找不到接受“System.Security.Principal.IPrincipal”类型的第一个参数的扩展方法“LastName”(是您缺少 using 指令或程序集引用?)
代码:
public class LabPrincipal : IPrincipal
{
private readonly LabIdentity _identity;
public LabPrincipal(LabIdentity identity)
{
_identity = identity;
}
public bool IsInRole(string role)
{
return
_identity.Roles.Any(
current => string.Compare(current, role, StringComparison.InvariantCultureIgnoreCase) == 0);
}
public IIdentity Identity
{
get { return _identity; }
}
public LabIdentity Information
{
get { return _identity; }
}
public bool IsUser
{
get { return !IsGuest; }
}
public bool IsGuest
{
get { return IsInRole("guest"); }
}
public int UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
【问题讨论】:
-
这可能是因为您有一个不知道
LastName的IPrincipal- 您可能需要将其转换为LabPrincipal才能访问这些附加属性
标签: asp.net-mvc