我创建了一个方法,该方法应该为使用会员资格的登录用户返回属性 soredin Active Directory。
我收到此错误The parameter 'username' must not be empty.
任何想法如何解决它?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.DirectoryServices.AccountManagement;
using System.Threading;
public static string SetGivenNameUser()
{
string givenName = string.Empty;
MembershipUser user = Membership.GetUser();
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal userP = UserPrincipal.FindByIdentity(ctx, user.UserName);
if (userP != null)
givenName = userP.GivenName;
return givenName;
}
堆
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) +2386569
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) +63
System.Web.Security.Membership.GetUser() +19