Jeff and .NET

The .NET musings of Jeff Putz

Sponsors

News

My Sites

Archives

When Session objects don't update

This is weird. I did that little HttpHandler that generates images in the simple NewsBlog app. It saves a sequence of characters to Session so the (hopefully not blind) user has to type in the stuff on the graphic and confirm they're a human.

On my dev machine, works like a champ running it from VS. I deploy it to the server, and it saves the first set of letters to Session, but subsequent calls do not. Here's the code from the handler...

    public void ProcessRequest(HttpContext context)
    {
    ...
        context.Session.Remove("antispamimage");
        context.Session.Add("antispamimage", s.ToString());
        context.Response.End();
    }


Why do you suppose it doesn't work right on the server?
Posted: Jan 05 2006, 01:22 AM by Jeff | with 10 comment(s)
Filed under:

Comments

John Walker said:

That should work, by I'm just curious....Couldn't you just to the following...

context.Session("antispamimage") = s.ToString();
context.Response.End();

Also, why the context.Response.End() line?
# January 5, 2006 2:00 AM

Jeff said:

I did set it that way originally... I was just trying other things for the sake of doing so.
# January 5, 2006 2:02 AM

Steven said:

Is the image cached on the browser?
# January 5, 2006 2:53 AM

Hannes Preishuber said:

another question: is this not a topic for a forum? and not for a blog?
# January 5, 2006 6:25 AM

zzzzzzzzzzzz said:

Hannes, surely jeff can post what he likes on his blog?
# January 5, 2006 7:20 AM

Wilco Bauwer said:

Does it work when you take out the context.Response.End() call? Response.End() will 'immediately' stop the execution of the page, by throwing a ThreadAbortException. It is likely that this results in not a session object that is not persisted properly.

For more information see Bertrand's blog post: http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx
# January 5, 2006 8:04 AM

Jeff said:

I'll have to try that, but it doesn't make sense that it works at home in the VS server but not in IIS.
# January 5, 2006 9:08 AM

AndrewSeven said:

It sort of makes sense that different server could have different behaviors.

Did you try on IIS "at home"?
# January 5, 2006 9:21 AM

Wilco Bauwer said:

I haven't looked into this, by my guess is that the difference is between IIS' worker request (which is ISAPIWorkerRequest or something like that) and Cassini's worker request (which is a derivation of SimpleWorkerRequest IIRC). Like AndrewSeven suggested - try the same thing at home on IIS and I am pretty confident that it will fail there aswell.
# January 5, 2006 10:18 AM

Jeff said:

Still no joy here... I don't get it. Doesn't make much sense that the Session update runs once but not on subsequent requests.
# January 5, 2006 8:53 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)