2011-05-21 177 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

相关问题