문제

in my web site, mobile number is userId, then some people has email,and some others no, how can i check one user has email or not?

MembershipUser mu = Membership.GetUser(username);
string userEmail = mu.Email.ToString();
if (!string.IsNullOrEmpty(userEmail))
{
  //do something
}

in above code i get error in 2nd line,any help?

도움이 되었습니까?

해결책

If your Email string is null, then ToSting()ing it will throw an exception. You should remove that method call. It's probably you're main problem.

What is the error?

Try debugging like this

    if (String.IsNullOrWhiteSpace(username))
            throw new ArgumentException("username is null or whitespace");

    MembershipUser mu = Membership.GetUser(username);
    if (mu == null)
        throw new ArgumentNullException("Couldn't get a membership user for that username");
    string userEmail = mu.Email; // email is already a string, do not invoke Tostring() on it

     if (!string.IsNullOrEmpty(userEmail))
     {
         //do something
     }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top