Createuser exception handling

Discussion in 'ASP .Net Web Services' started by John, Aug 28, 2006.

  1. John

    John Guest

    Hi

    I am using the membership createuser method but need to find the error when
    one arise. I am using the below code;

    Public Function CreateUser(ByVal Username As String, ByVal Password As
    String, ByVal Email As String, ByRef ErrMsg As String) As Boolean
    Try
    Membership.CreateUser(Username, Password, Email)
    CreateUser = True
    Catch ex As MembershipCreateUserException
    ErrMsg = ex.StatusCode
    CreateUser = False
    End Try
    End Function

    The problem is that as far as I can tell the ErrMsg always returns blank.
    What am I doing wrong?

    Thanks

    Regards
     
    John, Aug 28, 2006
    #1
    1. Advertising

  2. Hi John,

    You'll want to use one of the overloads to get the information you seek. It
    comes back in a MembershipCreateStatus value.

    Check the code below and see if it gives you an idea?

    Ken
    Microsoft MVP [ASP.NET]


    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
    Protected Sub Page_Load _
    (ByVal sender As Object, ByVal e As System.EventArgs)
    Dim status As MembershipCreateStatus
    Dim usr As MembershipUser
    usr = Membership.CreateUser("john", "abc123$#!!!", _
    "", _
    "Mother's maiden name", "Valerie", _
    True, status)
    If status = MembershipCreateStatus.Success Then
    usr.IsApproved = True
    Label1.Text = usr.UserName & " created."
    Else
    Label1.Text = "There was a problem: " & status.ToString
    End If
    End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:label runat="server" id="Label1"></asp:label>
    </div>
    </form>
    </body>
    </html>


    "John" <> wrote in message
    news:%...
    > Hi
    >
    > I am using the membership createuser method but need to find the error
    > when one arise. I am using the below code;
    >
    > Public Function CreateUser(ByVal Username As String, ByVal Password As
    > String, ByVal Email As String, ByRef ErrMsg As String) As Boolean
    > Try
    > Membership.CreateUser(Username, Password, Email)
    > CreateUser = True
    > Catch ex As MembershipCreateUserException
    > ErrMsg = ex.StatusCode
    > CreateUser = False
    > End Try
    > End Function
    >
    > The problem is that as far as I can tell the ErrMsg always returns blank.
    > What am I doing wrong?
    >
    > Thanks
    >
    > Regards
    >
     
    Ken Cox [Microsoft MVP], Aug 28, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Gilkey
    Replies:
    1
    Views:
    731
  2. =?Utf-8?B?UG9ydG1hbg==?=

    ASP.NET 2.0 Membership CreateUser method

    =?Utf-8?B?UG9ydG1hbg==?=, Jan 5, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,138
    =?Utf-8?B?UG9ydG1hbg==?=
    Jan 5, 2006
  3. VB Programmer
    Replies:
    3
    Views:
    932
    VB Programmer
    Jan 13, 2006
  4. John

    Createuser exception handling

    John, Aug 28, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    441
    Ken Cox [Microsoft MVP]
    Aug 28, 2006
  5. John

    Createuser exception handling

    John, Aug 28, 2006, in forum: ASP .Net Security
    Replies:
    1
    Views:
    125
    MikeS
    Aug 28, 2006
Loading...

Share This Page