在ASP.NET MVC应用程序中获取生成错误

时间:2013-07-12 09:31:46

标签: c# asp.net-mvc

我在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()'

那么我怎么能解决这个问题?

3 个答案:

答案 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)

班级的默认access modifierinternal。您应该将其更新为public

更改

class DomainContext

public class DomainContext