Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing additional validation with ASP.NET Membership Create Status
    primarykey
    data
    text
    <p>I personally find vague error messages a pain. In my new practice project I am trying to add additional validation to the user input. However, ASP.NET <em>MembershipCreateStatus</em> has Members; e.g. <strong><em>InvalidEmail</em></strong> that takes care of some of these areas when the <em>CreateUser Method</em> is used.</p> <p>I can do an if statement or Regex on the submitted email before the input reaches the <em>Membership.CreateUser Method</em>. However, I am not sure where to start with this:</p> <p>I know this question is a little subjective but I hate to find out later that there is a better way, and if you are just starting up, it can be a lifesaver.</p> <p>Should I create an additional validation Method to check for very specific formatting errors in the email, in addition to the system checking. As you can see the error message does not say why it is invalid.</p> <p>Also is it possible to create my own enum for example, email contains underscore, which I can attached to the <em>MembershipCreateStatus</em>? If so how?</p> <p>Here is my sample code, abbreviated:</p> <pre><code>public string GetErrorMessage(MembershipCreateStatus status) { switch (status) { case MembershipCreateStatus.InvalidEmail: return "The e-mail address provided is invalid."; default: return "Go to jail!!"; } } protected void btnSubmit_Click(object sender, EventArgs e) { try { Membership.CreateUser(txtUserName.Text, txtPassword.Text, txtEmail.Text); } catch (MembershipCreateUserException ex) { ltrStatusMsg.Text = GetErrorMessage(ex.StatusCode); } catch (HttpException ex) { ltrStatusMsg.Text = ex.Message; } } </code></pre> <p>Thanks my friends.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload