Mvc 中的 OnCreatingUser 相当于什么以及如何使用它
在我的 Web 表单应用程序中,我一直在连接我的 Asp.net 会员注册控件事件“OnCreatingUser”来检查用户名或电子邮件是否存在或者用户名是否合适。
Mvc 中的等效方法是什么以及如何使用它?
这是我的 Web 表单应用程序方法的一部分。
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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不能将 ASP.NET 2.0 Membership Web 服务器控件与 ASP.NET MVC Framework 一起使用,因为它们依赖于 MVC 不支持的 WebForms 回发模型。
您可以编写自己的控制器和视图来提供此功能。或者,您可能需要查看 ASP.NET MVC 会员入门工具包。
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.