Solved

Custom Error messages in MembershipProvider

Posted on 2007-11-16
11
905 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:BobCSD
  • 6
  • 5
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Did you find a solution?

Bob
0
 
LVL 1

Author Comment

by:BobCSD
Comment Utility
No.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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
 
LVL 1

Author Comment

by:BobCSD
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:BobCSD
Comment Utility
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
Comment Utility
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 1

Author Comment

by:BobCSD
Comment Utility
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
Comment Utility
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 1

Author Comment

by:BobCSD
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

12 Experts available now in Live!

Get 1:1 Help Now