【发布时间】:2012-02-08 07:17:24
【问题描述】:
当用户登录到我们的 MVC3 网络应用程序时,我们需要处理一些特定的事情,所以它在 global.asax.cs 中的连接如下:
public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
if (args.Context.Request.LogonUserIdentity != null)
{
MembershipUser mu = Membership.GetUser();
// blah blah ... kick off something special
// for logged in users here
}
}
现在我遇到了异常
System.InvalidOperationException: This method can only be called after the authentication event.
在args.Context.Request.LogonUserIdentity != null 那里避免绊倒Membership.GetUser(); 我怀疑选择使用FormsAuthentication_OnAuthenticate 不是一个合适的选择,我正在寻找合适的事件和功能(lifetime and events)没有明确的答案。
我真的走错方向了吗?处理这种情况的最佳事件/功能是什么?谢谢!
【问题讨论】:
-
Hm... LogonUserIdentity 当前 Microsoft Internet 信息服务 (IIS) 身份验证设置的 WindowsIdentity 对象。您正尝试从
FormsAuthentication_OnAuthenticate访问此属性。看起来很奇怪。 -
随便试试
Application_AcquireRequestState
标签: asp.net-mvc forms-authentication