Solved

Custom Error messages in MembershipProvider

Posted on 2007-11-16
11
910 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
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!

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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