[英]Trying to get a user's userID post authentication in MVC3 using ASP.NET memberships
当用户登录到我们的MVC3 Web应用程序时,我们需要处理一些特定的事情,因此将其连接到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
行中,该行args.Context.Request.LogonUserIdentity != null
其中,以避免绊倒Membership.GetUser();
args.Context.Request.LogonUserIdentity != null
我怀疑使用FormsAuthentication_OnAuthenticate
的选择不合适,我在寻找合适的事件和功能( 生命周期和事件 ),但没有明确的答案。
我真的在这个方向上走错了方向吗? 处理此案的最佳事件/功能是什么? 谢谢!
我遇到了同样的问题。 使用global.asax事件Application_AuthorizeRequest而不是FormsAuthentication_OnAuthenticate为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.