さて、私は最終的に解決策を思いつきました - これは有効な答えと見なすことができますか? 基本的に、カスタム AuthorizationFilter を作成し、セッションにフラグを設定して、すべての作業を 1 回だけ実行しました。ただし、一度だけ発生するイベント「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;
}
}