Asp.net mvc ASP.Net MVC 4:登录后仅在Windows身份验证后更新一次配置文件

Asp.net mvc ASP.Net MVC 4:登录后仅在Windows身份验证后更新一次配置文件,asp.net-mvc,asp.net-profiles,asp.net-authorization,Asp.net Mvc,Asp.net Profiles,Asp.net Authorization,我有一个内部网应用程序,设置了Windows身份验证以进行用户身份验证,这很好,唯一的问题是我不想说“你好,mydomain\user!”但是使用我在Active Directory中找到的用户的完整显示名称 事实上,我想用我们域中的更多细节来填充配置文件,问题是我只想在用户第一次调用应用程序时经过身份验证后,才执行此广告查询一次。我有所有的广告和个人资料的事情工作,但我没有找到一个好地方把代码,以便它被调用后,登录一次。我怀疑自定义属性可能是一种方式。。。非常感谢您的帮助。谢谢 尝试将信息存储

我有一个内部网应用程序,设置了Windows身份验证以进行用户身份验证,这很好,唯一的问题是我不想说“你好,mydomain\user!”但是使用我在Active Directory中找到的用户的完整显示名称


事实上,我想用我们域中的更多细节来填充配置文件,问题是我只想在用户第一次调用应用程序时经过身份验证后,才执行此广告查询一次。我有所有的广告和个人资料的事情工作,但我没有找到一个好地方把代码,以便它被调用后,登录一次。我怀疑自定义属性可能是一种方式。。。非常感谢您的帮助。谢谢

尝试将信息存储在会话中或客户端的cookie或本地存储中

嗯,我终于想出了一个解决办法——这算是一个有效的答案吗?基本上,我编写了一个定制的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;
        }
    }