asp.net:使用c#指定MembershipCreateStatus.ProviderError的错误

时间:2012-03-30 19:14:05

标签: c# asp.net asp.net-membership membership-provider

也许这个问题听起来很愚蠢。 在上述声明中,谁是提供者? 是程序员提供所需的错误,创建成员资格的用户还是其他人? 具体来说,我想在用户键入超过maxlength字符时显示错误,如下所示: PS。在geterrormessage方法中找到带*的行...

UsernameTextbox.MaxLength = 15;
    if (UsernameTextbox.Text.Length > UsernameTextbox.MaxLength)
    {
        status = MembershipCreateStatus.ProviderError;
        Msg.Text = GetErrorMessage(status);
    }


public string GetErrorMessage(MembershipCreateStatus status)
{
   switch (status)
  {


  case MembershipCreateStatus.DuplicateUserName:
    return "Username already exists. Please enter a different user name.";


  case MembershipCreateStatus.DuplicateEmail:
    return "A username for that e-mail address already exists. Please enter a different e-mail address.";

  case MembershipCreateStatus.InvalidPassword:
    return "The password provided is invalid. Please enter a valid password value.";

  case MembershipCreateStatus.InvalidEmail:
    return "The e-mail address provided is invalid. Please check the value and try again.";

  case MembershipCreateStatus.InvalidAnswer:
    return "The password retrieval answer provided is invalid. Please check the value and try again.";

  case MembershipCreateStatus.InvalidQuestion:
    return "The password retrieval question provided is invalid. Please check the value and try again.";

  case MembershipCreateStatus.InvalidUserName:
    return "The user name provided is invalid. Please check the value and try again.";
   //****** STAR LINE:i want to show the following message but i don't know if the-->
  //-->the provider error method can let me do this
  case MembershipCreateStatus.ProviderError:
    return "field outreached the maximum length of characters which is:";

  case MembershipCreateStatus.UserRejected:
    return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";

  default:
    return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
   }
 }

2 个答案:

答案 0 :(得分:1)

Provider是内置的默认MembershipProvider。您可以通过创建一个派生自MembershipProvider的类来指定您自己的实现。

在MSDN上查看本教程:http://msdn.microsoft.com/en-us/library/yh26yfzy.aspx

答案 1 :(得分:0)

身份验证提供程序“AspNetSqlMembershipProvider”返回错误。

了解更多信息http://go.microsoft.com/fwlink/?LinkID=177550