User982203039 posted
I am trying to get user information on my Intranet. I am successful with using
using (var context
= new PrincipalContext(ContextType.Domain,
"domain.local")) in my home controller. My question is how can I make this information available to ALL views? I saw an article on MyHelpers
view. I added the App_Code directory and added:
@using System.DirectoryServices.AccountManagement
@helper UserFullName()
{
using (var context = new PrincipalContext(ContextType.Domain))
{
var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name);
if (principal != null)
{
var fullName = string.Format("{0} {1}", principal.GivenName, principal.Surname);
@fullName
}
}
}
The issue is that the line @using System.DirectoryServices.AccountManagement give a error that says: Using directive is unnecessary. The type or namespace name 'DirectoryServices'
does not exists in the namespace 'System' (Are you missing as assembly refernense?) I do have this reference and am using the DirectoryService on a controller.
Any ideas on this issue? Or is there a better way to do what I am trying to do? I would like to have the user.Name and
user.EmailAddress from
DirectoryEntry directoryEntry = user.GetUnderlyingObject()
as DirectoryEntry; available to all my views along with checking for a certain group membership. Thanks!!
EB