尝试使用 ASP.NET 成员资格在 MVC3 中获取用户的用户 ID 后身份验证
当用户登录到我们的 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 是为了避免绊倒 Membership.GetUser();
我怀疑使用 FormsAuthentication_OnAuthenticate
的选择不是一个合适的选择我正在寻找适当的事件和函数(一生和事件),但目前还没有明确的答案。
我在这方面真的走错方向了吗?处理这种情况的最佳事件/函数是什么?谢谢!
We need to process something specific when the user logs into our MVC3 web app, so it's wired inside global.asax.cs as follows:
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
}
}
Right now I'm getting the exception
System.InvalidOperationException: This method can only be called after the authentication event.
at the line args.Context.Request.LogonUserIdentity != null
which is in there to avoid tripping over Membership.GetUser();
I suspect the choice of using FormsAuthentication_OnAuthenticate
is not an appropriate choice and I'm hunting for the appropriate event and function (lifetime and events) without a clear answer in sight.
Am I really off in the wrong direction on this one? What is the best event/function to hook into to process this case? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题。使用 global.asax 事件 Application_AuthorizeRequest 而不是 FormsAuthentication_OnAuthenticate 对我有用。
I was running into the same issue. Using the global.asax event Application_AuthorizeRequest instead of FormsAuthentication_OnAuthenticate worked for me.