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,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
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:
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


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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.