Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 6th, 2006, 12:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default Error when loading custom MembershipProvider

Does anyone know what exactly happens when ASP.NET loads a MembershipProvider. I know it calls Initialize with two arguments (friendly name and a string/value collection of configuration settings) but where does they come from? I guess it comes from web.config. Well I have implemented my own MembershipProvider and it works fine as long as I don't use any of the Login controls. I get an error message when I click logon with the Login control... Why? What do I need to implement in my custom provider? I don't get any runtime errors..

Thanks in advance for any help.

 - mega
Moving to C# .NET
__________________
 - mega
Aspiring JavaScript Ninja
  #2 (permalink)  
Old November 6th, 2006, 03:40 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

For some background about how instances of your providers are created and who calls what, take a look here: http://Imar.Spaanjaars.com/QuickDocId.aspx?QUICKDOC=380

Do you get any specific errors? "an error message when I click logon with the Login control" is a bit vague and makes it impossible to recommend a fix.

Normally, to implement a provider, you need to implement all required methods for the relevant class., e.g. MembershipProvider for a Membership provider.

Depending on your version of Visual Studio, it will implement method stubs in VB for all the required methods as soon as you type

Inherits MembershipProvider

In C# you can right click the name (e.g. MembershipProvider) and choose Implement Abstract class.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old November 6th, 2006, 07:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

Hi Imar.
Thanks for your reply.

I've read most of your article and I think it's a bit extreme to implement everything. I've found this Knowledge Base http://support.microsoft.com/default.aspx/kb/910440 which (apparently) shows an easy way of creating a custom MembershipProvider. My code looks pretty much like that. In my code I have implemented ValidateUser and GetUser. The Initialize method is just copy/paste from the article.

The error message is: Cannot load type Tetasoft.BookEvent.BusinessLogic.BookEventMembersh ipProvider (C:\Documents and Settings\Jon\Mis documentos\Visual Studio 2005\WebSites\BookEvent\web.config line 88).

In web.config I have this code snippet:
<membership defaultProvider="BookEventMembershipProvider" userIsOnlineTimeWindow="20">
    <providers>
      <clear />
      <add name="BookEventMembershipProvider"
        type="Tetasoft.BookEvent.BusinessLogic.BookEventMe mbershipProvider"
        connectionStringName="BookEventConnection"
        applicationName="BookEvent"
        passwordFormat="Clear"/>
    </providers>
  </membership>

I use Firebird as database - not that it should matter but now you know. Ohh and I use C# as programming language.

 - mega
Moving to C# .NET
  #4 (permalink)  
Old November 6th, 2006, 07:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null) // I have put a breakpoint here but it never gets hit
                throw new ArgumentNullException("config");


 - mega
Moving to C# .NET
  #5 (permalink)  
Old November 6th, 2006, 08:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

I'm working on a Windows XP Home edition right now. Maybe that can influence how the MembershipProvider is loaded? It's a long shot but I'm all out of ideas.

 - mega
Moving to C# .NET
  #6 (permalink)  
Old November 6th, 2006, 08:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

I took a look in the Temp ASP.NET folder and everything is there so everything seems to compile alright - another error source hits the dust.. hehe

 - mega
Moving to C# .NET
  #7 (permalink)  
Old November 6th, 2006, 08:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

Latest news!
The stack trace reveals that it is indeed a reflection error..
 at System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase)

So it must be my declaration in web.config that is the error source but it looks right, doesn't it?

 - mega
Moving to C# .NET
  #8 (permalink)  
Old November 6th, 2006, 09:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

Ok, I finally got tired of the vague exception message so I put my MembershipProvider and MembershipUser in my BL lib (where it belongs) and compile it. Then I added the assembly information to the provider declaration in web.config and tried running the website. I now get a message saying The type 'Tetasoft.BookEvent.BusinessLogic.BookEventMembers hipProvider' could not be loaded from the assembly 'BookEvent BuisnessLogic, Version=1.0.1.4000, Culture=neutral'. (C:\Documents and Settings\Jon\Mis documentos\Visual Studio 2005\WebSites\BookEvent\web.config line 88) I give up..
Code:
      <add name="BookEventMembershipProvider"
        type="Tetasoft.BookEvent.BusinessLogic.BookEventMembershipProvider,
             BookEvent BuisnessLogic,
             Version=1.0.1.4000,
             Culture=neutral"
        connectionStringName="BookEventConnection"
        applicationName="BookEvent"
        passwordFormat="Clear"/>
 - mega
Moving to C# .NET
  #9 (permalink)  
Old November 7th, 2006, 03:13 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I don't think your type attribute is correct. It should be:

type="ClassName, AssemblyName"


And indeed you don't need to implement everything. What's common is to create method stubs for all available methods, so you at least stick to the contract. Then from each method you can throw a NotImplementedException detailing the reason you didn't implement it.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #10 (permalink)  
Old November 7th, 2006, 09:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

I don't think I've explained myself very good, sorry. Let me try again.
Two months ago I wrote a MembershipProvider for this project. I didn't actually use it through any ASP.NET controls but I used it from code. E.g.
Code:
 _provider = new BookEventMembershipProvider();
             try
             {
                 if (_provider.ValidateUser(txtUserName.Text, txtPassword.Text))
                 {
                     _user = _provider.GetUser(txtUserName.Text, txtPassword.Text, true);
                     Cache.Insert(_user.UserName, _user);

The sharp ones will notice that the GetUser method is custom overloaded, hence no cast
It worked fine and my code was prepared for whatever control what uses MemberhipProvider. I did however get silent exceptions (that's exception that occur but doesn't influence the flow of the application - which makes them almost impossible to see) but I figured as long as it works..
What I did was to inherited from MembershipProvider and implement ValidateUser and GetUser + make a custom GetUser overload. The rest of the class was not implemented. E.g.
Code:
public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            throw new Exception("The method or operation is not implemented.");
        }

Now
I started out with having compiling problems because I moved a lot of code around due to my very manual refactoring (if you wanna know how asp.net 2.0 compile - read this: http://www.code-magazine.com/Article...uickid=0609061) but that's another story. Then I started reading about the MembershipProvider again and found the Knowledge Base article. I thought that it didn't compile because I hadn't implemented Initialize (weird but ok) - I did that, but still no cigar. In the meantime I discovered that the compile problem could be solved by right-clicking each page and choose build (then it would complain about some references and I would delete some letters and use Intellisense to restore the words), letting VS re-generate the reference code.

And that's where I was 24 hours ago (and still am).

PS. I haven't seen any official documentation on this but I know from experience that, it's type=FullClassName, AssemblyName*, VersionNumber, Culture,PublicKeyToken. E.g.
Code:
<DbProviderFactories>
    <clear/>

    <add name="FireBird Data Provider" invariant="FirebirdSql.Data.FirebirdClient"
        description="FirebirdClient - ADO.NET 2.0 Data Provider"
        type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory,
        FirebirdSql.Data.FirebirdClient, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=3750abcc3150b00c" />
  </DbProviderFactories>

* if I don't remove the dot from BookEvent.BuisnessLogic (my dll assembly) I get an error message saying that the assembly cannot be found
ASP.NET will try to get the information via reflection if you don't supply it here.

So why can't ASP.NET load my type?

 - mega
Moving to C# .NET
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
failed to login with membershipprovider swifty_programmer ASP.NET 2.0 Professional 3 May 4th, 2007 02:53 AM
failed to login with membershipprovider swifty_programmer ASP.NET 2.0 Basics 1 May 3rd, 2007 11:40 AM
how to use MembershipProvider.EncryptPassword kherrerab ASP.NET 2.0 Professional 1 March 14th, 2007 12:18 PM
Loading Error. Jack2Black Pro Visual Basic 2005 0 June 10th, 2006 10:33 AM
loading pages with custom size, toolbars etc dunc Javascript How-To 6 August 18th, 2004 04:37 PM



All times are GMT -4. The time now is 09:13 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.