I have an Intranet application with Windows authentication set for user authentication which works fine, only problem is that I do not want to say 'Hello, mydomain\user!' but use the user's full display name which I find in the Active Directory.
我有一个带有Windows身份验证的Intranet应用程序,用于用户身份验证,工作正常,唯一的问题是我不想说'Hello,mydomain \ user!'但请使用我在Active Directory中找到的用户的完整显示名称。
In fact I want to populate the profile with even more details from our domain, the problem is that I only want to do this AD query only once after the user has been authenticated on his first call to the application. I have all the AD and profile things working, but I do not find a good place to put the code so that it is called exactly once after login. I suspect a custom AuthorizeAttribute might be a way... Any help is greatly appreciated. Thanks!!
事实上,我想在我们的域中填充更多详细信息的配置文件,问题是我只想在用户第一次调用应用程序后对其进行身份验证后才执行此AD查询。我有所有AD和配置文件的工作,但我找不到一个放置代码的好地方,以便在登录后完全调用一次。我怀疑自定义AuthorizeAttribute可能是一种方式...非常感谢任何帮助。谢谢!!
2 个解决方案
#1
1
Try storing the information in session or within cookies or local storage on the client side.
尝试将信息存储在会话中或客户端的cookie或本地存储中。
#2
0
Well, I finally came up with a solution - can this be considered as a as a valid answer? Basically I wrote a custom AuthorizationFilter and put a flag into the session to do the whole work only once. However I hoped to find an event "User_Authenticated" which is fired only once. But I guess this is more appropriate for Forms authentication.
好吧,我终于提出了一个解决方案 - 这可以被认为是一个有效的答案吗?基本上我写了一个自定义的AuthorizationFilter并在会话中放置一个标志,只执行一次整个工作。但是我希望找到一个“User_Authenticated”事件,它只被触发一次。但我想这更适合表单身份验证。
public class ProfileUpdater : IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
// if there is a profile already in the session we do not update this
Controller controller = filterContext.Controller as Controller;
if (controller != null && controller.Session["ProfileUpdated"] != null)
{
return;
}
else if (controller == null)
{
return;
}
UserPrincipal domainUser = DomainHelper.GetDomainUser(controller.User.Identity.Name);
if (domainUser != null)
{
controller.Profile.SetPropertyValue("DisplayName", domainUser.DisplayName);
controller.Session["ProfileUpdated"] = true; // just put a marker object into the session to show we alreay updated the Profile
}
return;
}
}