Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Vestergaard 52 posts 138 karma points
    Nov 05, 2009 @ 14:54
    Thomas Vestergaard
    0

    HttpContext.Current.Session when using rest extensions

    Hey everybody

     

    I'm not really sure if this is a bug, or if it is even related to umbraco. I'm just hoping that someone can help me out here :)

    I have a method that can be acecssed via rest extensions. This works fine and all, but my HttpContext.Current.Session is null.

    This causes an issue as i'm using a third party component that tries to reset a session variable, which, obviously, creates a null refference exception.

    Does any of you guys know if this is related to Umbraco or asp.net in general?

     

    regards

    Thomas

  • Simon Justesen 436 posts 203 karma points
    Nov 05, 2009 @ 15:35
    Simon Justesen
    0

    You need to have your class inherit from IReadOnlySessionState to be able to read Session values

  • Simon Justesen 436 posts 203 karma points
    Nov 05, 2009 @ 15:39
    Simon Justesen
    0

    Err... sorry, that's only for HttpHandlers, but perhaps it will work anyway?

  • Thomas Vestergaard 52 posts 138 karma points
    Nov 05, 2009 @ 15:49
    Thomas Vestergaard
    0

    No IReadOnlySessionStatedid not do the trick.

    Right now, my class looks like this, and causses a NullReferenceException

    public class RestMethods

    {

       public static string TestContext() {

         if (HttpContext.Current.Session.IsNewSession)

           { return "is new session"; }

        return "is not a new session";

       }

    }

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Nov 05, 2009 @ 20:05
    Richard Soeteman
    0

    Hi Thomas,

    I think this is by design(not sure). The Rest extensions (aka /base) using reflection to instantiate and execute a method. When that happens I'm pretty sure you don't have a CurrentContext. Can you set a breakpoint and test if HttpContext.Current has a value?

    Cheers,

    Richard

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Nov 05, 2009 @ 20:33
    Thomas Höhler
    0

    I had the same problem and it is as Richard said: they don't have the the actual HttpContext. Solution will be to implement an HttpHandler instead or an aspx site which returns the json or xml or pure text as you want.

    hth, Thomas

  • Thomas Vestergaard 52 posts 138 karma points
    Nov 05, 2009 @ 20:55
    Thomas Vestergaard
    0

    For Richard: Yes, HttpContext.Current is looking pretty normal.

    For Thomas: I think I stranded the same place. From what I can find on the great internet, I need to make a HttpHandler instead if I want to use the session.

    However, I have found a workaround so the third party component does not need the session.

    Problem solved i Guess ;)

     

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 21, 2010 @ 16:15
    Rune Grønkjær
    0

    Anyone else have any inputs. I really need Session in my base methods. Can't really use them if they don't know the current session.

    My version is 4.5.2 and My Request and Respone all works like a charm through HttpContext.Current. There's just no Session.

    Anyone?

    /Rune

  • Chad Rosenthal 272 posts 474 karma points
    Dec 21, 2010 @ 05:23
    Chad Rosenthal
    0

    Did you figure this out? I'm having the same issue at the moment.

    Thanks,

    C

     

  • Rune Grønkjær 1371 posts 3102 karma points
    Dec 21, 2010 @ 08:11
    Rune Grønkjær
    0
Please Sign in or register to post replies

Write your reply to:

Draft