Ecnalyr
Ecnalyr

Reputation: 5802

Difficulty using MembershipProvider.GetUserNameByEmail - will not compile?

I am getting this error:

An object reference is required for the non-static field, method, or property 'System.Web.Security.MembershipProvider.GetUserNameByEmail(string)

When trying to use the code:

string userName = MembershipProvider.GetUserNameByEmail(email);

From my controller:

[HttpPost]
public ActionResult ChangeEmail(ChangeEmailViewModel model)
{
    if (ModelState.IsValid)
    {
        string email = model.Email;
        string userName = MembershipProvider.GetUserNameByEmail(email);
        if (userName != null)
        {
            // change email
        }
        else
        {
            // don't allow email change as that email is already in use
        }
    }
}

I do not understand why I am getting the error as I have found examples of this code being used and cannot see the difference?

Upvotes: 0

Views: 794

Answers (1)

Tuan
Tuan

Reputation: 5412

Try Membership.GetUserNameByEmail(email).

Upvotes: 4

Related Questions