簡體   English   中英

嘗試使用ASP.NET成員資格在MVC3中獲得用戶的userID發布身份驗證

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM