[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Custom Error messages in MembershipProvider

Posted on 2007-11-16
11
Medium Priority
?
913 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

830 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