PC Review


Reply
Thread Tools Rate Thread

Createuser exception handling

 
 
John
Guest
Posts: n/a
 
      28th Aug 2006
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


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      28th Aug 2006
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 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>


"John" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resume Exception After Handling Exception in C# beginner Microsoft C# .NET 9 18th Jan 2008 04:27 PM
Exception Handling =?Utf-8?B?WUM=?= Microsoft ASP .NET 4 26th Jun 2006 01:01 PM
Handling an exception inside an exception's constructor? Rick Microsoft C# .NET 4 1st Mar 2006 08:14 PM
Publish exception to Email in Exception Handling Exception Block =?Utf-8?B?ZW15?= Microsoft C# .NET 1 31st Mar 2005 12:45 PM
exception handling using SQLClient - is this the only exception that is caught??? James Cooke Microsoft VB .NET 2 18th Sep 2003 06:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:46 AM.