+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Session NULL in MVC widget

Session NULL in MVC widget

1 posts, 0 answered
  1. kaarthick
    kaarthick avatar
    1 posts
    Registered:
    04 Jul 2016
    02 Aug
    Link to this post

    I have a controller called Authenticate Controller.

    I have created a MVC widget using authnticate controller. The code has a session value stored in an object. I ran this locally it works fine. When i add as a widget and insert into a page / template it throws following error:

    NullReferenceException: Object reference not set to an instance of an object.

    CODE:

    [ControllerToolboxItem(Name="Authenticate",Title="Authenticate",SectionName="MVCWidget")]
        public class AuthenticateController : Controller
        {
            private Authentication oSessionAuthRequest;
         
            public Authentication SessionAuthRequest
            {

                get
                {
                    if (oSessionAuthRequest == null)
                    {
                        oSessionAuthRequest =(Authentication)Session[Constants.SessionKey]; //Session is null.

    //NullReferenceException: Object reference not set to an instance of an object.
                    }
                    return oSessionAuthRequest;
                }
                set
                {
                    Session[Constants.SessionKey] = value;
                }
            }
    }

    STACK TRACE FOR ERROR

    [NullReferenceException: Object reference not set to an instance of an object.] System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value) +718 Telerik.Sitefinity.Mvc.ControllerActionInvoker.DeserializeControllerProperties(MvcProxyBase proxyControl) +2079 Telerik.Sitefinity.Mvc.ControllerActionInvoker.TryInvokeAction(MvcProxyBase proxyControl, String& output) +265 Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy.ExecuteController() +89 System.Web.UI.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Control.PreRenderRecursiveInternal() +240 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4090

1 posts, 0 answered