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

CSBlogs : Remember Me fix

This was bugging me so I thought I'd take a look and see why commenter names and URLs were not being remembered in CS.  I thought it had something to do with the Cookies settings in the CS System Configuration panels, but the issue turned out to be much more obvious and required all but 2 minutes.

Check out the code below from CommentForm.cs.  Take no more than 14 seconds.  See it?

BlogPostResults result = WeblogPosts.Add(entry, CurrentUser, out postID);
if(result == BlogPostResults.Success &&  postID > 0)
 Context.Response.Redirect(BlogUrls.Instance().CommentPosted(DataSource,CurrentWeblog));
 
if(chkRemember.Checked)
{
 HttpCookie userCookie = new HttpCookie( "CommentUser" );
 userCookie.Values.Add("Name", tbName.Text);
 userCookie.Values.Add("Url", tbUrl.Text);
 Context.Response.SetCookie(userCookie);
}

Yeap.  The redirect was executing and the cookie was never being set.  Move the if(result == BlogPostResults....) lines with the Redirect() below the if(chkRemember.Checked) block.  Set the cookie, THEN redirect.

 

Comments (6) | Post RSS RSS comment feed

Posted on 3/31/2005 2:32:00 PM by Dave Burke
Categories: Community Server
Tags:

Related posts

Comments (6) -

4/10/2005 3:58:32 PM Permalink

This seems to be working well for you, the Remember Me "fix". It don't work for me though...

This is my resultant code after changing to what I THOUGHT it was supposed to be, but not so sure since it doesn't work;
if(chkRemember.Checked)
if(result == BlogPostResults.Success &&  postID > 0)
  Context.Response.Redirect(BlogUrls.Instance().CommentPosted(DataSource,CurrentWeblog));
{
  HttpCookie userCookie = new HttpCookie( "CommentUser" );
  userCookie.Values.Add("Name", tbName.Text);
  userCookie.Values.Add("Url", tbUrl.Text);
  Context.Response.SetCookie(userCookie);
}

S'at look right?

vern |

4/10/2005 6:16:13 PM Permalink

Vern:  Nope.  The  { HttpCookie userCookie block goes after the if (chkRemember.Checked) line.  Move the if (result == ...) and following line to below the final } bracket in your excerpt and you got it.

Or in other words:

if(chkRemember.Checked)
{
  HttpCookie userCookie = new HttpCookie( "CommentUser" );
  userCookie.Values.Add("Name", tbName.Text);
  userCookie.Values.Add("Url", tbUrl.Text);
  Context.Response.SetCookie(userCookie);
}

if(result == BlogPostResults.Success &&  postID > 0)
  Context.Response.Redirect(BlogUrls.Instance().CommentPosted(DataSource,CurrentWeblog));

daveburke |

3/22/2006 7:03:07 AM Permalink

I realize this is quite old, but I have to ask;
wasn't there a similiar problem in .Text? I seem to recall there was, and I thought you had a fix, but I can't locate anything on it.
I figured I'd ask you since your a Super-Coder and might have some guidance for a lowly hacker like me...

THANKS!!!

vern |

3/22/2006 7:07:43 AM Permalink

By the way, perhaps in the move to 2.0, your problem seems to have partially reappeared;
I am "remembered" by dbvt.com, but the button is not checked. Shouldn't it be?

vern |

3/22/2006 7:09:03 AM Permalink

Hey, Vern!  Always great to hear from you, as always.  I don't remember a specific .text problem with this, but then again you're going a long way back, dude.  You still using .text and having trouble is comments info being remembered?

daveburke |

3/22/2006 7:14:27 AM Permalink

I DO remember how this has worked in CS (and .text, too.)  Once you're remembered, the cookie has been laid and will be used on EVERY subsequent visit back to the page.  You're remembered only once and the deed is done.  I remember with one version of .text or CS (I forget which), I actually added an "Unremember me" checkbox that removed the cookie, since there is none in .text or CS.

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke