MembershipCreateStatus status; Membership.CreateUser("username", "password", "email", "question", "answer", true, out status); string statusString = status.ToString(); Console.WriteLine(statusString); // Output: Success
MembershipCreateStatus status; try { Membership.CreateUser("invalidusername", "password", "email", "question", "answer", true, out status); } catch (MembershipCreateUserException ex) { status = ex.StatusCode; } string statusString = status.ToString(); Console.WriteLine(statusString); // Output: InvalidUserNameIn this example, an exception is thrown when trying to create a membership account with an invalid username. The exception is caught and the status code is retrieved from the exception object. The ToString() method is then used to get the string representation of the status. Package library: System.Web.Security