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?
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?
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.
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.
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
You need to have your class inherit from IReadOnlySessionState to be able to read Session values
Err... sorry, that's only for HttpHandlers, but perhaps it will work anyway?
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";
}
}
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
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
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 ;)
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
Did you figure this out? I'm having the same issue at the moment.
Thanks,
C
Yes in Umbraco 4.6.
Read more in this forum post: http://our.umbraco.org/forum/developers/api-questions/13819-Session-acces-in-base-methods
/Rune
is working on a reply...