我在ASP.NET MVC中的Models文件夹下创建了两个类: -
namespace TMS.Models
{
public class ADIntigration
{
public static DomainContext GetUserDetails()
{
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain))
{
IPrincipal principal = HttpContext.Current.User;
WindowsIdentity identity = ((WindowsIdentity)principal.Identity);
UserPrincipal user = UserPrincipal.FindByIdentity(pc, identity.Name);
if (principal != null)
{
return new DomainContext() {
userGuid = user.Guid,
DisplayName = user.DisplayName,
GivenName = user.GivenName,
EmailAddress = user.EmailAddress
};
}
}
return null;
}
}
}
&安培;
namespace TMS.Models
{
class DomainContext
{
public class domainContext
{
public Nullable<Guid> userGuid { get; set; }
public string DisplayName { get; set; }
public string GivenName { get; set; }
public string EmailAddress { get; set; }
}
}
}
但是我收到了一个构建错误: -
可访问性不一致:返回类型'project.Models.DomainContext' 比方法更难获得 'project.Models.ADIntigration.GetUserDetails()'
那么我怎么能解决这个问题?
答案 0 :(得分:3)
如果您忽略public
中的class DomainContext
,那么它将被视为internal class DomainContext
,其可访问性低于public class ADIntigration
。
因此,您需要将class DomainContext
更改为public class DomainContext
答案 1 :(得分:0)
将class DomainContext
更改为public class DomainContext
答案 2 :(得分:0)