Custom Membership Provider: Calling Initialize problems - which config section?
Posted on 2007-10-15
I am using a custom membership provider and I need to be able to validate against 3 different tables so I wrote a helper function that updates the variables set during the initialize sub.
Problem is when I try to validate a user not using a login control but my own I need to know how to initilize the membership provider, specifically how to pass the proper web config section. So I figure I would create a New Sub that called the initialize:
My Page Code Behind for the login page:
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnLogin.Click
Dim provider As New AliveMediaMembershipProvider
Dim loginSuccess As Boolean = provider.ValidateUserByType(txtEmail.Text, txtUserPassword.Text, "Physicians", "Id, FirstName, LastName, Email, UserPassword", "Email", "UserPassword", "Id")
If loginSuccess Then Response.Redirect("~/physicians/Physician.aspx")
My New Sub inside my mebership provider that calls initialize:
Public Sub New()
Dim config As Collections.Specialized.NameValueCollection = ConfigurationManager.GetSection("system.web.membership.providers")
Inherited Initilize Sub that gets called:
Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Specialized.NameValueCollection)
If config("connectionStringName") Is Nothing OrElse config("connectionStringName").Trim() = "" Then
Throw New ArgumentException("Connection string is not configured in web.config, add connectionStringName")
membershipTable = config("membershipTable")
// more code
I get an Object Reference not set error on this I believe because I an not passing in the proper value for the config.