Error in ForumThreadView when a user is anonymous

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
6/20/2008 2:58:15 PM
ulu
Gravatar
Total Posts 22

Error in ForumThreadView when a user is anonymous

Hi,

After an upgrade to the trunk version, I'm getting an error when I try to view a forum thread with an anonymous post.

System.InvalidCastException: Object cannot be cast from DBNull to other types.

Line 42: </div>
Line 43: <div class="forumpostuserattribute">
Line 44: <portal:ForumUserThreadLink id="lnkUserPosts" runat="server" UserId='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"UserID")) %>' TotalPosts='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"PostAuthorTotalPosts")) %>' />
Line 45: </div>
Line 46: </div>

ulu

6/21/2008 6:38:31 AM
Gravatar
Total Posts 18439

Re: Error in ForumThreadView when a user is anonymous

Hi Ulu,

Can you do svn update again, then rebuild, then visit /Setup/Default.aspx

I implemented a change that should fix this but I haven't tested it so please let me know if it does or not.

In general I recommend not allowing anonymous posts. Support for that is not well implemented in mojoportal. It really ought to have a captcha for anonymous posts otherwise you will start getting a lot of spam in your forums.

Best,

Joe

6/23/2008 4:55:06 AM
ulu
Gravatar
Total Posts 22

Re: Error in ForumThreadView when a user is anonymous

Hi Joe,

Thanks, it works now.

I permitted anonymous posts in one forum initially, since I was interested in getting more posts. It worked at that time, but after an upgrade it stopped working. After I started getting spam, I disallowed anonymous posts, but the ones that are there already have to be visible.

Thanks again

Ulu

7/27/2008 9:31:23 PM
Gravatar
Total Posts 10

Re: Error in ForumThreadView when a user is anonymous

I'm using the latest release and this error is still happening on my site.  Anonymous posts are saved to the DB but the error is hit when the displaying the post.

7/28/2008 5:55:44 AM
Gravatar
Total Posts 18439

Re: Error in ForumThreadView when a user is anonymous

Yes, nothing has changed in the forums in this release. I still recommend not allowing anonymous posts. Support for that was implemented poorly at first and now over time it has become broken. What I should have done for this release was disable or remove that option so people will stop trying to use it until we implement it correctly. I will do that (hide the option) for the next release as actually implementing correct support for anonymous is not a high priority for me at the moment. If someone else wants to implement it thats fine with me but its not something I plan to work on in the immediate future so my advice is don't allow anonymous posts.

Sorry if this is not the answer you were hoping for.

Best,

Joe

7/28/2008 6:25:31 AM
Gravatar
Total Posts 18439

Re: Error in ForumThreadView when a user is anonymous

I decided to take a quick look at this and see if I could fix the error at least. When I tested it on my local machine there was no error, but I'm running a newer version than the release so I looked and it turns out I did recently already fix the error, but it was after the new release.

You can fix it on your installation if you edit the stored procedure: mp_ForumPosts_SelectByThread

The problem was caused by null being returned for the user post count when the user doesn't exist. You can fix it by changing this:

'PostAuthorTotalPosts' = up.TotalPosts,

to this:

'PostAuthorTotalPosts' = COALESCE(up.TotalPosts, 0),

this will convert the null to 0 and prevent the error. Its still a very poor implementation, the name of the anonymous user is hard coded to "Guest" in the stored procedure so its not even localizable. As I mentioned before, since there is no captcha implemented in the forum, allowing anonymous posts is going to invite a lot of spam, so its still porrly implemented even with this fix.

Hope it helps,

Joe

 

7/28/2008 2:42:32 PM
Gravatar
Total Posts 10

Re: Error in ForumThreadView when a user is anonymous

Hello Joe,

Thanks for the info.  I'll apply that change to the SP.

I agree that allowing anonymous posts is a bad idea just as a general practice and I don't doubt that my client may find himself realizing that further down the road.  For now, I'm just implementing the forums as requested.

I'll check out the source code and see if it might be an easy enough fix to just prevent the cast at the calling end if DBNull is returned.  That might be a better fix, in the long run.  However, I'll definitely apply your change to the SP for a quick resolution.

Thanks again,

Lloyd

7/29/2008 7:46:01 AM
Gravatar
Total Posts 18439

Re: Error in ForumThreadView when a user is anonymous

Hi Lloyd,

The stored proc fix is the correct fix, not a workaround, it needs to be not null because we are databinding to a control that expects to bind to integer data. Its the control that links to a user's posts and indicates the total posts by the user, if the user is anonymous then it needs to be 0 not null.

This is now fixed in mojoPortal 2.2.6.6 which I just released afew minutes ago.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.