Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Remember Me fix for CS 2.0

I've had conversations with cyberpals and read CS forum threads about the "Remember me" Comment Form checkbox not working, and without a solution that I've seen.  I knew it wasn't working on my blog, that's for sure.  I was determined to get to the bottom of it during last night's geek session.  It took longer than it should have, but I nailed the sucker.

The "Remember Me" checkbox remembers the name and blog address of anonymous (non-registered) users who add comments in Community Server.  It's supposed to create a cookie that's read the next time the user visits the site so they don't have to re-enter their name and blog URL.  It's simply common courtesy.  But since "Remember me" wasn't working, everyone who visited my blog and was good enough to leave a comment had to type their name and URL on each visit. 

When digging into the CommentForm.cs class I found that the cookie was being saved correctly, but the retrieved cookie was always null on return visits.  Why was the retrieved cookie null?  That was where I focused.

I should add here that the subject of cookies and authentication can be rather confusing in Community Server, only because Community Server supports so many different authentication methods: Windows (Active Directory), ASP.NET Forms, heck, even Passport authentication.  Added to that you have shared authentication with other ASP.NET applications, the ASP.NET Membership Provider, shared authentication among multiple (virtual) CS Communities, sub-communities sharing authentication of a parent, and multi-server authentication to name a few.  I'm still trying to get my head around this stuff.  One thing I do know is that Cookies play a role in most of these schemes, particularly with shared authentication.  I mention this because the Remember Me issue has NOTHING to do with any of those things.  Remember Me is a separate cookie that saves and retrieves a name and a URL field on the Blog and Gallery Comment Form.  And that's all it does.

So after confusing myself (and burning up precious latenight mental cycles) thinking the issue was something more complicated than it was, I focused in on the issue at hand and stumbled on the simple solution.  I added an .Expires property when saving the cookie in the btnSubmit_Click() method of the CommentForm.cs class.

userCookie.Expires = DateTime.Now.AddYears(1);

That did it.  You good folk who comment on this blog, I now welcome you back with full Remember Me functionality!

[tags: Community Server, CSComments]

Comments (2) | Post RSS RSS comment feed

Posted on 6/8/2006 8:33:00 PM by Dave Burke
Categories: Community Server
Tags:

Related posts

Comments (2) -

6/9/2006 3:58:38 AM Permalink

Oh Dave,
You didn't look in the one place you should have! Don't you remember I brought this very subject with you a while back?

I even blogged my solution back in April - blogs.crankygoblin.com/.../141948.aspx

Now, while I'm sure my solution is better than yours (sorry, couldn't resist Smile the important thing is that by studying it you've learnt a whole new chunk of the code Smile

Geoff Appleby |

6/9/2006 6:27:43 AM Permalink

Busted!

You're absolutely right, Geoff.  I remember now.  And yeah, you even sent me an email on it! Geez. In my defense, the second week of April I had just lost my old job and things were weird, definitely in transition.  I wasn't in my normal Community Server Groove, in other words.

I read your post and wondered when in the HECK did you get an .Expires property on setting that cookie!  Cause like you, I sure didn't see one in CS 2.0 or CS 1.1.  (I didn't look at my CS 1.0 source.)  Then I re-read it and saw that it was a crafty dotText move.  Heh!  

I enjoyed how you refactored it out.  In my dotText days I did the very same thing, which allows one to say  "Refactoring the RememberCookie() method is so....dotText!" Smile  But yeah, I had an option for people who wanted to REMOVE their cookie, since as it is now, and even with your sweet refactored bits, there's no such option.  Once you're remembered, you're remembered for life.  Which is cool, but since we're being uber-nerds on the topic, thought I'd mention it.

One other point is that I wasn't being remembered in either firefox or IE.

Sorry to muscle in on your fix, dude.  You planted the flag first.

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke