alivemedia
asked on
Custom Membership Provider: Calling Initialize problems - which config section?
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.ImageClickEv entArgs) Handles btnLogin.Click
Dim provider As New AliveMediaMembershipProvid er
Dim loginSuccess As Boolean = provider.ValidateUserByTyp e(txtEmail .Text, txtUserPassword.Text, "Physicians", "Id, FirstName, LastName, Email, UserPassword", "Email", "UserPassword", "Id")
If loginSuccess Then Response.Redirect("~/physi cians/Phys ician.aspx ")
End Sub
My New Sub inside my mebership provider that calls initialize:
Public Sub New()
Dim config As Collections.Specialized.Na meValueCol lection = ConfigurationManager.GetSe ction("sys tem.web.me mbership.p roviders")
Initialize("AliveMediaMemb ershipProv ider", config)
End Sub
Inherited Initilize Sub that gets called:
Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Special ized.NameV alueCollec tion)
MyBase.Initialize(name, config)
If config("connectionStringNa me") Is Nothing OrElse config("connectionStringNa me").Trim( ) = "" Then
Throw New ArgumentException("Connect ion string is not configured in web.config, add connectionStringName")
Else
membershipTable = config("membershipTable")
End If
// more code
End Sub
I get an Object Reference not set error on this I believe because I an not passing in the proper value for the config.
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.ImageClickEv
Dim provider As New AliveMediaMembershipProvid
Dim loginSuccess As Boolean = provider.ValidateUserByTyp
If loginSuccess Then Response.Redirect("~/physi
End Sub
My New Sub inside my mebership provider that calls initialize:
Public Sub New()
Dim config As Collections.Specialized.Na
Initialize("AliveMediaMemb
End Sub
Inherited Initilize Sub that gets called:
Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Special
MyBase.Initialize(name, config)
If config("connectionStringNa
Throw New ArgumentException("Connect
Else
membershipTable = config("membershipTable")
End If
// more code
End Sub
I get an Object Reference not set error on this I believe because I an not passing in the proper value for the config.
Instead of ConfigurationManager.GetSe ction("sys tem.web.me mbership.p roviders") could you try ConfigurationManager.GetSe ction("sys tem.web/me mbership/p roviders") ?
ASKER
I still get this error when doing that:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Source Error:
Line 25: MyBase.Initialize(name, config)
Line 26:
Line 27: If config("connectionStringNa me") Is Nothing OrElse config("connectionStringNa me").Trim( ) = "" Then
Line 28: Throw New ArgumentException("Connect ion string is not configured in web.config, add connectionStringName")
Line 29: Else
Here is the portion of my web.config if that helps:
<membership defaultProvider="AliveMedi aMembershi pProvider" >
<providers>
<add name="AliveMediaMembership Provider" type="AliveMediaMembership Provider" connectionStringName="mdsp otsConnect ionString" membershipTable="Administr ator" username="Username" password="Password" setAdditionalCookies="True " cookieList="ID, EmpID, FirstName, LastName, Email" selectFields="Username, Password"/>
</providers>
</membership>
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept
Source Error:
Line 25: MyBase.Initialize(name, config)
Line 26:
Line 27: If config("connectionStringNa
Line 28: Throw New ArgumentException("Connect
Line 29: Else
Here is the portion of my web.config if that helps:
<membership defaultProvider="AliveMedi
<providers>
<add name="AliveMediaMembership
</providers>
</membership>
I'm only going on what I would do if I was trying to access an attribute in a normal XML file. But you could try prefixing the any attributes you are trying to retrieve with an @ symbol.
scrap that last answer, it's probably rubbish, have you set a breakpoint on your function to see what values are contained within the collection?
ASKER
It's returning nothing, I even tried just doing a GetScetion("system.web") and still get nothing in the collection. I am assuming GetSection only works of user defined sections of the web.config. At a stand still here :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Closed, 500 points refunded.
modus_operandi
Community Support Moderator
modus_operandi
Community Support Moderator
I found this which looks appears to work so far as I have implemented it.
http://www.lazyasscoder.co m/Article. aspx?id=69 &title=How +To%3a+Man ually+init ialize+a+c ustom+memb ership+pro vider
http://www.lazyasscoder.co