UmbracoApiController Session Data with IIS not working
I am submitting this post as an act of desperation and hope someone might have some thoughts on the following:
I have an API Controller based on UmbracoApiController that uses and relies on Session variables.
(I have a need for this regardless of the fact that it violates REST principles).
I also use Session variables in the my mvc controllers.
Umbraco.Web.Mvc.RenderMvcController
When I am developing and running the web site in IIS Express, both of the types of controllers work just fine. I.E. :
HttpContext.Session["SOMVEVARIABLE"] works perfectly.
When I move the site to IIS though, the controllers based on the RenderMVC Controller work perfectly as well.
The Controllers based on UmbracoApiController on the other hand have a null Session.
I have searched and searched and have come up empty handed. I am hopeful that someone else has experienced this and might have some suggested work arounds or fixes.
I saw this post, and my current code is a little beyond this in that I already have full authentication working for both the umbraco web site controllers and the web api controllers. I have similar logic as this thread. My real dillema is that it works perfectly in iisexpress, but in iis, it works great except for the web api.
I have considered a work around with a pure WebApi controller since I have that working in IIS just fine. But it needs access to the umbraco media and content management functions. I am still working on this work around but it would be nice if I could divine why iis is not working and iisexpress does work. In the long run what I am using the session variables for creates a nice elegant solution with no work arounds.
To answer your question I have a web site based on umbraco that divvies up web content and allows end users to create content. Part of this site is a game that requires a child to log in, establish a connection and then create a session with the server for requests. To follow REST in a pure fashion is cost prohibitive to pass the entire game state each time since there is alot of information that is transient but required to be somewhat persistent. A database solution would work but is overkill for this particular scenario and would be time consuming to implement . Session state is a perfect solution for this... but is not working in iis.
I have considered using a windows service via a tcp/ip socket to do the same but my game environment does not like the socket technology for all platforms. Therefore the simplest solution was REST and works wonderfully in iis express...
So I turned to the community to see if anyone else might have some thoughts, since Microsoft tech support is no help because it works fine as a mvc web api only solution and does not fall apart until I add umbraco to the equation.
It is a sticky wicket....
Thank you for your response, any other ideas are certainly welcome.
Could you not convert UmbracoApiController to a UmbracoController and just return a JsonResult. If Session is 100% required seem like an alternative. I've always kept WebApi stateless.
Also is the server you're testing IIS on Load Balanced? If it is and you're running Session State in Proc you'll lose it when/ if the LB directs you to a different server.
I removed the requirement for my web api to not need session variables as a short term solution. It is a bit painful since we have to move the entire game state to the server and back to the client every api call, but it gets me moving for now.
I am still investigating why they will not work on my iis server. If anyone else has any thoughts on why they won't work in umbraco, I would love to hear from you.
UmbracoApiController Session Data with IIS not working
I am submitting this post as an act of desperation and hope someone might have some thoughts on the following:
I have searched and searched and have come up empty handed. I am hopeful that someone else has experienced this and might have some suggested work arounds or fixes.
Thank you
Robert
Hi Robert
I'm not sure this is a good idea, the UmbracoAPIController is based on Web API, and therefore the session is null...
There is a discussion on stack overflow that might help:
http://stackoverflow.com/questions/9594229/accessing-session-using-asp-net-web-api
it has some workaround suggestions and also the warnings about performance!
Sorry to not be very helpful :-(
What are the variables that need to be in session?
could this be handled in a different way?
regards
Marc
I saw this post, and my current code is a little beyond this in that I already have full authentication working for both the umbraco web site controllers and the web api controllers. I have similar logic as this thread. My real dillema is that it works perfectly in iisexpress, but in iis, it works great except for the web api.
I have considered a work around with a pure WebApi controller since I have that working in IIS just fine. But it needs access to the umbraco media and content management functions. I am still working on this work around but it would be nice if I could divine why iis is not working and iisexpress does work. In the long run what I am using the session variables for creates a nice elegant solution with no work arounds.
To answer your question I have a web site based on umbraco that divvies up web content and allows end users to create content. Part of this site is a game that requires a child to log in, establish a connection and then create a session with the server for requests. To follow REST in a pure fashion is cost prohibitive to pass the entire game state each time since there is alot of information that is transient but required to be somewhat persistent. A database solution would work but is overkill for this particular scenario and would be time consuming to implement . Session state is a perfect solution for this... but is not working in iis.
I have considered using a windows service via a tcp/ip socket to do the same but my game environment does not like the socket technology for all platforms. Therefore the simplest solution was REST and works wonderfully in iis express...
So I turned to the community to see if anyone else might have some thoughts, since Microsoft tech support is no help because it works fine as a mvc web api only solution and does not fall apart until I add umbraco to the equation.
It is a sticky wicket....
Thank you for your response, any other ideas are certainly welcome.
Could you not convert UmbracoApiController to a UmbracoController and just return a JsonResult. If Session is 100% required seem like an alternative. I've always kept WebApi stateless.
Also is the server you're testing IIS on Load Balanced? If it is and you're running Session State in Proc you'll lose it when/ if the LB directs you to a different server.
That is not a bad suggestion. I will give that a shot later today. No, IIS is not in a load balanced scenario.
Thanks for the suggestion,
Robert
I removed the requirement for my web api to not need session variables as a short term solution. It is a bit painful since we have to move the entire game state to the server and back to the client every api call, but it gets me moving for now.
I am still investigating why they will not work on my iis server. If anyone else has any thoughts on why they won't work in umbraco, I would love to hear from you.
Thank you!
is working on a reply...