Reputation: 13
HELP......Just moved to C# from vb and Im really lost with this.
var ldapmembershipUser = (LdapMembershipUser)System.Web.Security.Membership.GetUser("username");
var cnAttributeValues = ldapmembershipUser.Attributes["cn"];
Code bails at cnAttributeValues with Object reference not set to an instance of an object.
I dont know how to set it as a new ?? Object?
This is in reference to the nJupiter google controls.
Upvotes: 1
Views: 252
Reputation: 2229
You need to check that the user exists first before trying to get the attributes.
Upvotes: 1
Reputation: 887867
That would mean that GetUser
returned null
, probably because there is no user with that name.
Upvotes: 1
Reputation: 1502696
Membership.GetUser(string)
is documented to return:
A MembershipUser object representing the specified user. If the username parameter does not correspond to an existing user, this method returns Nothing.
So that's what's happening here - ldapmembershipUser
is null because there's no such user. You should check for that and act accordingly:
// Note name casing change here to keep my sanity.
if (ldapMembershipUser == null)
{
// Take appropriate action
}
Note that you could also have problems if GetUser
returns a reference to an object which isn't an LdapMembershipUser
.
Upvotes: 3