Avatar of flukester
flukester
 asked on

custom membership provider

I am trying to mock up a custom membership provider to our in house database. I've created the class, login page, etc... I am getting the following error: Could not load type 'iPMNMembershipProvider'.

It might be something to do with my folder structure, but I've been moving things around and can't figure it out.

So as a root level folder I have CustomMembershipProviderTest. In that folder I have an App_Code folder that contains my class iPMNMembershipProvider.vb.

At the root level of the site (same level as CustomMembershipProvider, not within that folder) I have a web.config file that contains the following:

Edit: Forgot to add the code from the beginning of my class file:
Public Class iPMNMembershipProvider
    Inherits MembershipProvider
    Private conn As String
    Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Specialized.NameValueCollection)

        conn = ConfigurationManager.ConnectionStrings("web_ipmnConnectionString").ConnectionString
        MyBase.Initialize(conn, config)

    End Sub



<membership defaultProvider="iPMNMembershipProvider">
			<providers>
				<add name="iPMNMembershipProvider" 
             type="iPMNMembershipProvider" 
             requiresQuestionAndAnswer="false" 
             enablePasswordRetrieval="true" 
             enablePasswordReset="true" 
             connectionStringName="web_ipmnConnectionString"/>
			</providers>
		</membership>
 
<add name="web_ipmnConnectionString" connectionString="Data Source=SQLSERVER; Initial Catalog=ipmn; User ID=xxx;pwd=xxxxxv; Integrated Security=True" providerName="System.Data.SqlClient"/>

Open in new window

ASP.NET

Avatar of undefined
Last Comment
kingofnothing

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Craig Wardman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
flukester

ASKER
Should the App_Code file be within the CustomMembershipProviderTest folder or outside at the root level?
Craig Wardman

App_code folder is normally in the website root. However using the app_code folder is only necessary when using the old style 'web site' instead of a 'web project'

Confirm that u are not using the folder within a web project as I have noticed that files in the app_code folder aren't compiled unless u manually change to 'compile' instead of 'content' on the files properties.

If all is ok, generally speaking ur folder structure has no impact on the namespace of your class (unless u keep the naming conventions the same, which is recommeded as good practice)
flukester

ASKER
Okay, I'm just not getting this, I apologize.
I tried using the same path that I use for uploads, but that doesn't work. When you say fully qualified, does that mean drive letter:/folder1/folder2/......
From the examples I see it's namespace, class, but I don't know what my first namespace is. This is on our dev server. I am attaching a screen shot of the class view.


Untitled-1.jpg
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Craig Wardman

there should be no paths involved, so you dont need to worry about the location on disk..

looking at your class view, its directly in the root.. but your website must have a root namespace, even if its the assembly name..

go into a codebehind file and type 'global. '

see what namespaces are offered to you by intellisense and keep using intellisense on the correct namespaces to find 'iPMNMembershipProvider' - when you find it, use that in your web.config.
flukester

ASKER
The website is an website that has been added to for many years, it wasn't started as an asp.net website. We have just added asp.net applications to it. When I type global.  I get right to the iPMNMembershipProvider namespace. See attached.
Untitled-1.jpg
Craig Wardman

Hmm, in your web config can u use global.iPNM.... With any success?

U might need to precompile the class into a dll to get this to work. Put it in a class library and then add a reference to the project in ur website. By doing this it will generate a proper assembly, namespace and classname for the type.  
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Meds

You can try to enclose your provider inside a namespace. Open up your "iPMNMembershipProvider.vb" and do the example below. Then in your webconfig


<providers>
                        <add name="iPMNMembershipProvider"
             type="YourApplicationNameSpace.iPMNMembershipProvider"
             requiresQuestionAndAnswer="false"
             enablePasswordRetrieval="true"
             enablePasswordReset="true"
             connectionStringName="web_ipmnConnectionString"/>
                  </providers>


Hope this helps.
Namespace YourApplicationNameSpace
Public Class iPMNMembershipProvider
    Inherits MembershipProvider
    Private conn As String
    Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Specialized.NameValueCollection)
 
        conn = ConfigurationManager.ConnectionStrings("web_ipmnConnectionString").ConnectionString
        MyBase.Initialize(conn, config)
 
    End Sub
End Class
End Namespace

Open in new window

flukester

ASKER
I ended up creating a class library and building out a dll to reference in my bin folder so I could fully qualify the namespace.
kingofnothing

http://www.shiningstar.net/ASPNet_Articles/CustomProvider/CustomProvider7.aspx

for any one who will searching on building custom membership provider (vb.net)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23