2011-05-21 180 views
1

我使用Activedirectory作爲成員資格提供程序。我想將當前登錄的用戶存儲在會話中。獲取當前登錄用戶

protected void user_login_LoggedIn(object sender, EventArgs e) 
{ 
    MembershipUser user = Membership.GetUser(); 
} 

上面的代碼,給出以下的


The parameter 'username' must not be empty. 
Parameter name: username 

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

異常詳細信息的錯誤:

System.ArgumentException: The parameter 'username' must not be empty. 
Parameter name: username 

源錯誤:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

堆棧跟蹤:

[ArgumentException: The parameter 'username' must not be empty. 
Parameter name: username] 
    System.Web.Util.SecUtility.CheckParameter(String& param, Boolean checkForNull, Boolean checkIfEmpty, Boolean checkForCommas, Int32 maxSize, String paramName) +1976411 
    System.Web.Security.ActiveDirectoryMembershipProvider.CheckUserName(String& username, Int32 maxSize, String paramName) +30 
    System.Web.Security.ActiveDirectoryMembershipProvider.GetUser(String username, Boolean userIsOnline) +86 
    System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +82 
    System.Web.Security.Membership.GetUser() +19 
    darts.login.user_login_LoggedIn(Object sender, EventArgs e) in E:\Projects\DARTS\source\darts\darts\login.aspx.cs:24 
    System.Web.UI.WebControls.Login.OnLoggedIn(EventArgs e) +111 
    System.Web.UI.WebControls.Login.AttemptLogin() +179 
    System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101 
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 
    System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118 
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166 
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 

版本信息:Microsoft .NET Framework版本:2.0.50727.4211; ASP

+0

嗨,尼克。感謝編輯 – 2011-05-21 23:39:20

回答

0

編輯:

基於使用這個從ASP.NET獲取有關當前已驗證用戶的登錄信息,我看到這可能工作一對夫婦的方式。首先,如果您使用Active Directory成員資格提供程序使用表單身份驗證,則可以在該處捕獲用戶名。然後,您只需將GetUser()方法中的用戶名放在裏面:GetUser(yourUser),您應該獲得所需的信息。

如果這不是一個選項,我相信用戶名信息存儲在您的登錄控制下(在您的情況下,如果您確實使用登錄控件,我相信名稱爲user_login)。你會簡單地說user_login.username,並將其放在GetUser()方法中。

最後,你可以嘗試舊的回退HttpContext.Current.User.Identity.Name,並把它放在你的GetUser()方法中。

+0

嗨比格斯,感謝您的答案。這給當前登錄的窗口用戶。我使用Active Directory作爲成員資格提供者。因此,登錄該網站的用戶可以是來自AD的任何人。我想獲得登錄的用戶名 – 2011-05-21 23:44:30

+0

@Vivek Chandraprakash - Ahhh,我明白了。讓我看看它,看看我能看到什麼。 – IAmTimCorey 2011-05-21 23:51:49

+0

@Vivek Chandraprakash - 我更新了我的帖子,以反映我對您問題的新理解。由於舊信息無助,因此我決定將其刪除。 – IAmTimCorey 2011-05-22 00:09:41

相關問題