Createuser exception handling

J

John

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
 
K

Ken Cox [Microsoft MVP]

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$#!!!", _
"(e-mail address removed)", _
"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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top