My first MVC widget & null session state.
Hello everyone.
I've just spent this morning setting up a new SF 5.1 website running on IIS 7 and have built an MVC widget. currently the set up is as follows:
Home page with a login
Logged in page with a link to an MVC page
MVC page that contains solely the MVC widget; the widget being a straight port of an MVC webapp I have been working on.
I've got it all up and running for the most part (i.e. it builds and I can hit an MVC view) but I am struggling with session state.
Attached you will find a picture of the controller structure. As you can see, I have a generic, 'common' controller and another 'standard' controller that calls into/inherits from this common controller.
Below you will find exerts from these controller classes:
Standard
namespace SitefinityWebApp.MVC.Controllers
[ControllerToolboxItem(Name = "HealthChecker", Title="Healthchecker", SectionName="Healthchecker") ]
public class HealthCheckerController : HealthCheckerCommon
public ActionResult Start()
try
var localId = new Guid("EAEA9495-2A03-4E1E-B362-090466359A76");
var data = (from r in db.Reviews where r.AccountId == localId select r);
return View(data);
catch (Exception ex)
ExceptionHelper.WriteLog(ex);
return RedirectToAction("Error");
namespace SitefinityWebApp.MVC.Controllers
public class HealthCheckerCommon : Controller
public void SaveModelToSession(CalculationQuestion model)
try
Session[string.Format("0_model", model.ReviewId)] = model;
catch (Exception ex)
ExceptionHelper.WriteLog(ex);
return;
I am interested to see Telerik's response to this.
Are you calling this code and seeing the null within your controller or from the Razor view?
Hi Dan.
The exception is being thrown within the controller itself.
Give me an hour or so, and I'll put some more detail up in my original post (time to give my daughter stories!).
I only popped this up quickly in the hope that it was a common issue.
No rush on my end, I may not be able to help on this quite yet. I am still learning the interactions between Sitefinity and MVC too.
If it had been an MVC issue (data not passing between Controller and View), I would most likely have the answer for you. But seeing as it may be an issue between Sitefinity and the Controller, that's an area I am also interested in, but not proficient in yet.
Hmmmm...so it looks like it is just not liking session state in my controller.
Attached you will find the state of HttpContext in side and out of SF.
Inside SF = NullSession.png
Outside SF = NotNullSession.png
Now obviously something is not playing ball here and as I have noted, is this an issue with HttpSessionStateWrapper?
Hopfeully this is just me not knowing Sitefinity that well and Iwill be able to adjust the config to get this up and running!
Hello Dan - how reliable are Telerik at answer on the forums themselves?
i.e. Am I better off submitting a support ticket?
Yes ticket, I thought these MVC posts were being monitored since it was so new, but really Telerik support on the sitefinity forums seems almost non-existant now, it's hard to know if anyone working on MVC there has seen it without an official reply.
Please update us with the details\response :)
Hello Steve.
I thought as much so dropped in a support ticket earleir this morning.
As soon as I hear anything, I'll let you konw the response.
Is it me being really stupid or is this a little odd?!
I dont think so, it was sold as being native MVC, so it should work right?...I can use sessions variables in webforms fine.
Excellent - I'm still relatively new to this hwole development game and thought I was missing something blindingly obvious.
Has anyone else tried creating/accessing sessions in controllers within a SF MVC website?
Hello,
sorry for not getting into this thread sooner.
Unfortunately, I am not able to reproduce this issue. I have recorded a short video demonstrating how to work with session:
http://screencast.com/t/AGTz6HkpU
We'll need to get the whole sample to investigate what exactly seems to be the problem. Without more information, I'd guess that there is a problem with sessions in general - could you try to use sessions in Sitefinity in something that's not MVC?
I've seen you've also opened a ticket, so we can continue the troubleshooting over there.
In general, the HttpContext passed to the Controller is simply a wrapper around the original HttpContext, so there is no reason why this would not work.
Other thing that comes to mind could be caching. Try turning off the caching of the page on which you have placed the widget that uses the session and see if the problem persists.
Hope this helps.
Greetings,
Ivan
the Telerik team
Hello Ivan
I'll make sure session is working first of all outside of MVC then get back to you.
Thanks for lookign into this and I will be in touch shortly.
Hi,
I believe I figured out why the session state shown in the video worked but Richard received a NULL session state in his test environment. The session state shown in the video used a Hybrid Template. From my testing, using a MVC widget in a hybrid template has a valid session state. The problem occurs when you use a MVC widget in a Pure MVC Template. In this scenario, the session state is NULL. I have recorded a video and submitted a bug ticket to Sitefinity. Hope this helps clears things up.
Hello Bobby.
Thanks for looking into this. Indeed you are right that this does have the same effect but I had set the page to Hybrid rather than Pure so something else is afoot.
I've submitted a support ticket (on the 31st) and so far I have had three different Sitefinity folk replying saying they need a bit more time to find a solution.
As such, I think something else is kicking about under the bonnet causing a bit of grief.
When I get a solution or response with what's going on, I'll post it up here.
Hi Richard,
I was wondering if you already got a response from Telerik about this issue. I have the same problem here (running the website in SF 5.4.4010).
Thanks in advance!
Regards,
Peter
Hello Peter.
I opened a support ticket, went through a load of things but alas Telerik were unable to reproduce the issue.
I started up a blank project and used Sitefinity Thunder to add an MVC widget from scratch and it did appear to work ok.
As a result, try using SF Thunder to register everything properly and if you have already done that, I'm at a loss.
All I kow is that mine definitely was broken so somethingdefinitely got screwed up somewhere. Best of luck.
Hello,
The problem seems to be caused by a setting to the site either in web.config or in the .csproj file as when testing the same on new project it all works as expected.
All the best,
Stanislav Velikov
the Telerik team