Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Custom Error messages in MembershipProvider

Posted on 2007-11-16
11
Medium Priority
?
912 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

610 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