我的一个控制器中有以下代码。无论控制器如何,如何使它可用于所有视图?
谢谢
using (var context = new PrincipalContext(ContextType.Domain, "domain.local"))
{
var user = UserPrincipal.FindByIdentity(context, username);
DirectoryEntry directoryEntry = user.GetUnderlyingObject() as DirectoryEntry;
if (user != null)
{
Session["UserName"] = user.Name;
Session["EmailAddress"] = user.EmailAddress;
}
}