Solved

Custom Error messages in MembershipProvider

Posted on 2007-11-16
11
907 Views
Last Modified: 2012-08-13
I have created a custom MembershipProvider, and in the code there, is there a way to override the messages that display in the controls for log in and registration....

For instance, in the CreateUser() Function, instead of sending back the DuplicateEmail message, I need to send a custom message as shown in the comment below. Is that possible to override these "red" messages that are displayed?

        If RequiresUniqueEmail AndAlso GetUserNameByEmail(email) <> "" Then
            'status = "You already have an account. Request a forgot login reminder."
            status = MembershipCreateStatus.DuplicateEmail
            Return Nothing
        End If

thanks
0
Comment
Question by:Starr Duskk
  • 6
  • 5
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20327597
Did you find a solution?

Bob
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 20330293
No.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20350031
1) Did you start with MembershipProvider or SqlMembershipProvider as the base?

2) I am not sure that I understand what you mean by "these "red" messages that are displayed".

Bob
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 2

Author Comment

by:Starr Duskk
ID: 20351679
It Inherits MembershipProvider.

and Imports System.Data.SqlClient.

In the log in or other control, when the log in fails, it displays an error message... If I break the control into a template it is this:

<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20353257
Aaah, yes, you're talking about the Login control *GRIN*.

Here are some configuration settings for the Login control:

            Me.Login1.FailureText = "You're an idiot if you can't remember your login!!!"
            Me.Login1.CreateUserText = "New user"
            Me.Login1.DisplayRememberMe = False
            Me.Login1.FailureAction = LoginFailureAction.RedirectToLoginPage
            Me.Login1.FailureTextStyle.ForeColor = Color.Red
            Me.Login1.InstructionText = "Me is an instruction"
            Me.Login1.LabelStyle.ForeColor = Color.SteelBlue
            Me.Login1.LoginButtonText = "Start me up"
            Me.Login1.LoginButtonType = ButtonType.Link
            Me.Login1.Orientation = Orientation.Vertical
            Me.Login1.PasswordLabelText = "Enter a password:"
            Me.Login1.PasswordRecoveryText = "Password recovery is impossible"
            Me.Login1.PasswordRequiredErrorMessage = "You're really a moron if you think you can't enter a password"
            Me.Login1.RememberMeSet = True
            Me.Login1.RememberMeText = "Pretty please, remember me!!"
            Me.Login1.TextLayout = LoginTextLayout.TextOnLeft
            Me.Login1.TitleText = "Log into the System"
            Me.Login1.TitleTextStyle.BorderStyle = BorderStyle.Outset
            Me.Login1.UserNameLabelText = "User:"
            Me.Login1.UserNameRequiredErrorMessage = "You really don't know who you are?"
            Me.Login1.VisibleWhenLoggedIn = False

Bob
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 20354134
But the question is, am I able to set this via my custom MembershipProvide in the validateuser function?

I thought Me.Login1 would only apply to the codebehind for that page class?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20354475
The MembershipProvider doesn't have any knowledge of the Login control--it is the other way around.  The Login control uses the MembershipProvider to determine if the user can be authenticated, and then displays the messages.

Bob
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 20354535
I understand how the membershipprovider is setup, but my validation function goes through several things and I want to return an appropriate message based on where the failure is. So how does the membershipprovider return back to the login page which area it failed on?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 20354544
Here is what the Login control does:

Private Sub AttemptLogin()
    If ((Me.Page Is Nothing) OrElse Me.Page.IsValid) Then
        Dim e As New LoginCancelEventArgs
        Me.OnLoggingIn(e)
        If Not e.Cancel Then
            Dim args2 As New AuthenticateEventArgs
            Me.OnAuthenticate(args2)
            If args2.Authenticated Then
                FormsAuthentication.SetAuthCookie(Me.UserNameInternal, Me.RememberMeSet)
                Me.OnLoggedIn(EventArgs.Empty)
                Me.Page.Response.Redirect(Me.GetRedirectUrl, False)
            Else
                Me.OnLoginError(EventArgs.Empty)
                If (Me.FailureAction = LoginFailureAction.RedirectToLoginPage) Then
                    FormsAuthentication.RedirectToLoginPage("loginfailure=1")
                End If
                Dim failureTextLabel As ITextControl = DirectCast(Me.TemplateContainer.FailureTextLabel, ITextControl)
                If (Not failureTextLabel Is Nothing) Then
                    failureTextLabel.Text = Me.FailureText
                End If
            End If
        End If
    End If
End Sub

 
Bob
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 20375710
Well, it didn't really answer my question of how to pass the value from the custom Membershipprovider back to the text in the log in control, but I want to close this question and get it out of my open list. So...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20377445
It doesn't send anything back, it just sets the Text for the failure control:

Dim failureTextLabel As ITextControl = DirectCast(Me.TemplateContainer.FailureTextLabel, ITextControl)
If Not failureTextLabel Is Nothing Then
   failureTextLabel.Text = Me.FailureText
End If

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection String 16 54
Master Content Pages, WebForms, and Session Variables 1 43
Need a starter for ETL protocol? 4 55
IIS redirect 1 65
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

9 Experts available now in Live!

Get 1:1 Help Now