Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Custom Profile Provider with NHibernate

    I've updated the NHibernate blog example code to include a custom profile provider.  This provider stores the profile information using the XML data type in SQL Server 2005.  New profile properties can be added to the web.config file in same way as the Microsoft SqlProfileProvider.  The included web.config contains examples showing how to add new properties and their types.  If adding a custom type be sure to include the full type name (i.e. NHBlog.BusinessEntities.Security.Application.).

    The example now includes custom NHibernate based providers for Membership, Roles, and Profiles.


Posted 08-09-2007 8:29 AM by anortham
Attachment: NHBlog.zip

[Advertisement]

Comments

Jack Ma wrote re: Custom Profile Provider with NHibernate
on 08-14-2007 1:16 AM

Sorry but where is that .zip attachment?

jack wrote re: Custom Profile Provider with NHibernate
on 08-14-2007 4:46 AM

After setting up the database and building the solution, I launched the web site; and then I started to sign up a user, but soon after I clicked the button I got a very common .NET exception:

Server Error in '/NHBlog.WebUI' Application.

--------------------------------------------------------------------------------

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 92: public override string ApplicationName

Line 93: {

Line 94: get { return application.ApplicationName; }

Line 95: set { application = new DaoFactory().GetApplicationDao().GetByApplicationName(value); }

Line 96: }

Source File: G:\Resources\orm\NHibernate\NHBlog\NHBlog.DataAccess\Security\NHibernateMembershipProvider.cs    Line: 94

Alan wrote re: Custom Profile Provider with NHibernate
on 08-14-2007 9:41 AM

Jack:

I forgot to mention that you have to manually create an application in the applications table.  Add one named NHBlog and that should fix your error.

Tommy wrote re: Custom Profile Provider with NHibernate
on 08-16-2007 6:46 AM

I can't get this to work. It complaints about the membership providers type attribute in web.config. The error isn't in english but I guess an attempted translation to english would be something like "configuration error, failed under activation" (ish).

jack wrote re: Custom Profile Provider with NHibernate
on 08-16-2007 11:16 PM

Alan, you rock, now error fixed! Thanks for this great series, and I am looking forward the next post... :P

- Jack

Alan wrote re: Custom Profile Provider with NHibernate
on 08-17-2007 9:16 AM

Tommy:

I don't think you are getting the real cause of the error in the output you are seeing.  Run dbgview (www.microsoft.com/.../debugview.mspx) while testing so you can capture the log4net output from NHibernate.  Look for the first exception thrown and it should give you a better idea of what's causing the problem.

Gerard Alberts wrote re: Custom Profile Provider with NHibernate
on 09-06-2007 3:48 PM

Hi great reading I got this working after all, will analyze it further this weekend to really get NHibernate under my thumb. There's a small error in PostDetail.aspx.cs: here's the correct Page_Load, works if you replace it:

   protected void Page_Load(object sender, EventArgs e)

   {

       Post post = new DaoFactory().GetPostDao().GetById(postID);

       if (post != null && post.Comments == null)

       {

           foreach (Comment c in post.Comments)

           {

               log.Debug(c.Depth);

           }

       }

   }

Alan Northam wrote re: Custom Profile Provider with NHibernate
on 09-10-2007 12:19 PM

Gerard,

Thanks for pointing that out.  I made some major changes to the underlying code in this project and was in a bit of a hurry to refactor the presentation.  You will probably find some more odd looking code :)

Bryan Bass wrote re: Custom Profile Provider with NHibernate
on 04-25-2008 3:11 PM

Alan,  

Thanks for all this work. The ZIP attached to this article appears to be corrupt or invalid.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)