Solved

Custom MembershipCreateStatus message

Posted on 2007-11-15
3
924 Views
Last Modified: 2013-11-07
I have created a custom MembershipProvider class.

In it, I am checking:

        ' check if application requires a unique email and if the email already exists...
        If RequiresUniqueEmail AndAlso GetUserNameByEmail(email) <> "" Then
            status = MembershipCreateStatus.DuplicateEmail
            Return Nothing
        End If

Instead of having it print to the screen the default message that the email already exists, I want to send my own custom message instead. How do I override the message for the MembershipCreateStatus.DuplicateEmail?

thanks.
0
Comment
Question by:Starr Duskk
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 20292034
Bob,
Didn't we go over that here?
http://www.experts-exchange.com/Microsoft/Development/.NET/.NET_Framework_2.0/Q_22950749.html

With the relevant example from MSDN here:
http://msdn2.microsoft.com/en-us/library/system.web.security.membershipcreatestatus.aspx

I don't know what your full function is (is it returning a string?), but within what you posted:
If RequiresUniqueEmail AndAlso GetUserNameByEmail(email) <> "" Then
            status = MembershipCreateStatus.DuplicateEmail
            Return Nothing
End If

since you have the status, you can use the MSDN "GetErrorMessage" function almost the way it is on MSDN...just change the string text in fn.

even if your full function isn't returning a string, you can pass in a string variable by ref and use the GetErrorMessage function to set the string variable...
0
 
LVL 1

Author Comment

by:Starr Duskk
ID: 20316428
The previous example was in a click event in the codebehind of a log in page. and the Msg.Text is being set to the return value from a function which is also in the log in page:

Msg.Text = GetErrorMessage(status)

I am not using a log in page click event. If I wanted to, that would certainly likely do it.

My question is in regard to setting the returned message from within the custom membership provider, not having to setup an error handling routine on every page that uses the membership provider. I would have to setup a click event and an errorhandling routine for login, change password, register, forgot password, all that good stuff. And I know when I hit the membership provider functions what my error message should be, so I want to set it in there and have it return it to the red error message.

I mean, microsoft is getting these messages from somewhere... so I should be able to override the value returned within my custom membership provider... one would think.... without having to write a detailed click event and error handler.




0
 
LVL 1

Author Comment

by:Starr Duskk
ID: 20377372
oh well. want to clear this out.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now