|
-
Oct 18th, 2008, 06:21 PM
#1
Thread Starter
Fanatic Member
[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:
Imports Microsoft.VisualBasic
Public Class customSqlMembership
Inherits SqlMembershipProvider
Public Overrides Function ValidateUser(ByVal email As String, ByVal password As String) As Boolean
Dim username As String
username = Membership.GetUserNameByEmail(email)
If Not String.IsNullOrEmpty(username) Then
Return MyBase.ValidateUser(username, password)
Else
Return False
End If
End Function
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:
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.
-
Oct 19th, 2008, 07:43 PM
#2
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|