Thread: Wrox Blog
View Single Post
  #9 (permalink)  
Old May 8th, 2007, 01:31 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

quote:"Object reference not set to an instance of an object." on This line "Dim userId As Guid = CType(Membership.GetUser().ProviderUserKey, Guid)"
You're probably not logged on then.

Membership.GetUser() returns the current user when logged in or Nothing when you're not logged in. So, when you're not logged in, you try to get the ProviderUserKey from Nothing which won't work.
quote:Do I need to add an UserId column to the BlogEntry table in order to do this? or just change the ID column to an uniqueidentfire?
You seem to be missing some fundamental knowledge about what it is that you want to do, and how to do it.

I think you need to take a step back from the code, take a piece of paper and write things down. Make a few diagrams, draw some classes that are shown in the book as well, and then decide what you need.

If you do that, you can answer questions like this one easily yourself. Think about the question: how would changing the Id column into a Guid help you? Are all your visitors only allowed to post once? How will you clearly identify unique BlogEntries when people can post more than one entry?

So the answer is: no, don't change it, but add it. That way, you have an Id column to uniquely identify the item in the table, and a PostedBy column to get the Guid of the MembershipUser that posted it.

Does this help?


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.