Results 1 to 2 of 2

Thread: [2008] General question on inheritance.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    [2008] General question on inheritance.

    I am a bit confused about inheritance now. I thought I knew how to use it properly but I just got very confused.

    I am making a asp.net website (or correctly, updating an existing one I made) and in this I would like to make my login authenticate using email/password rather then username/password.

    SO, I am using thee default sql membership provider if anyone has experience with it. I create a class and inherit it.

    vb.net Code:
    1. Imports Microsoft.VisualBasic
    2.  
    3. Public Class customSqlMembership
    4.     Inherits SqlMembershipProvider
    5.  
    6.     Public Overrides Function ValidateUser(ByVal email As String, ByVal password As String) As Boolean
    7.  
    8.         Dim username As String
    9.         username = Membership.GetUserNameByEmail(email)
    10.  
    11.         If Not String.IsNullOrEmpty(username) Then
    12.             Return MyBase.ValidateUser(username, password)
    13.         Else
    14.             Return False
    15.         End If
    16.    
    17.     End Function
    18.  
    19. End Class

    Now to my knowledge, I thought it would execute the function JUST LIKE IF I DIDNT override it.. Because I am basically calling the validate user function from the base class (which is the default which works with a username/password and works BEAUTIFULLY).

    Quote from MSDN:
    Takes, as input, a user name and a password and verifies that they are valid-that is, that the membership data source contains a matching user name and password. ValidateUser returns true if the user name and password are valid, if the user is approved (that is, if MembershipUser.IsApproved is true), and if the user isn't currently locked out. Otherwise, it returns false.
    Following a successful validation, ValidateUser updates the user's LastLoginDate and fires an AuditMembershipAuthenticationSuccess Web event. Following a failed validation, it fires an

    AuditMembershipAuthenticationFailure Web event.
    so as you can see, I dont think the base call in my overridden function calls the event even if its True.

    what happens is that, I am "successfully" logged in with that code. However, on a couple of my pages (such as profile.aspx) I do make a call to get the data of the current logged in user. This is done by calling:

    vb.net Code:
    1. Dim username as string = Membership.GetUser().Username

    Again, it works if I dont override it.. but if I do override it then It gives me a:
    Object reference not set to an instance of an object
    so why does it "log" me in (ie, says "welcome .. [username]" and lets me access pages that are protected, but NOT set an instance of the membership object.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: [2008] General question on inheritance.

    Can you post your code that you use to instantiate the customSQLMembership class and invoke the ValidateUser method? Have you tried debugging it to see the program flow?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width