开发者

What is the equivalent of OnCreatingUser in Mvc and how to use it

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
}


I don't think you can use the ASP.NET 2.0 Membership web server controls with the ASP.NET MVC Framework because they rely on the WebForms postback model which isn't supported by MVC.

You can write your own controller and views to provide this functionality. Alternatively, you may want to look at the ASP.NET MVC Membership Starter Kit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜