In my Web forms applications I had been wiring my Asp.net membership register controls event "OnCreatingUser" to do my checks for whether the user name or email exits or if the user name is appropriate.
What is the equivalent method in Mvc and how is it used?
Here is part of my method from a web forms application.
public void cuwRegister_CreatingUser(object sender, LoginCancelEventArgs e)
{
TextBox textBox = (TextBox)cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("txtCaptchaTextBox");
if (textBox.Text != Session["CaptchaImageText"].ToString())
{
// Should not proceed. Go back to Register.aspx and let visitor try again.
e.Cancel = true;
}
TextBox txtUserName = (TextBox)cuwRegister.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
if (IsUserNameObscene(txtUserName.Text) || (!IsUserNameValid(txtUserName.Text.Trim())))
{
DisplayMessage("Please choose a different User name.", "alert");
e.Cancel = true;
}
if (txtUserName.Text.Length < 4)
{
DisplayMessage("Please choose a User name more than 4 characters.", "alert");
e.Cancel = true;
}
}
private void DisplayMessage(string msg, string css)
{
// Display message in label in page
}