mvc4.0 html.actionlink comfired,ASP.Net MVC 4:登录后只进行一次Windows身份验证后更新配置文件...

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;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值