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

Forums / Developing with Sitefinity / Error while creating custom event indexing with session state

Error while creating custom event indexing with session state

10 posts, 0 answered
  1. gopalraman gopal
    gopalraman gopal avatar
    52 posts
    Registered:
    03 Dec 2009
    28 Apr 2010
    Link to this post
    hi

    while creating custom indexing from sitefinity, i got the following error and i cant index the event module also.

    Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.

    Please help me to make custom indexing.


    Thanks
    G.GopalRaman
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Apr 2010
    Link to this post
    Hi gopalraman gopal,

    Could you, please try to enable the Session state in the <pages> configuration section of your web.config:
    <pages enableSessionState="true">
        <controls>
            ...
        </controls>
    </pages>



    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. gopalraman gopal
    gopalraman gopal avatar
    52 posts
    Registered:
    03 Dec 2009
    28 Apr 2010
    Link to this post
    Hi Radoslav Georgiev

    I triend this also. But no luck. Is there any problem in Custom Indexing?

    Thanks
    G.GopalRaman
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Apr 2010
    Link to this post
    Hi gopalraman gopal,

    Unless you give us more detailed information, there would be no way that we could tell what the issue is. What code are you using for indexing, which uses session state? Could you please show us a piece of the code where you are getting the error. Also the complete stack trace would help a lot.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. gopalraman gopal
    gopalraman gopal avatar
    52 posts
    Registered:
    03 Dec 2009
    28 Apr 2010
    Link to this post
    hi

    This is the code i added for events indexing. But not working. I added all this cs files inside App_Code - > EventsIndexProvider folder


    //EventIndexerInfo.cs
     

    using System.Collections;
    using System.Text;
    using Telerik.Framework.Search;
    using System;

    namespace EventIndex
    {
        /// <summary>
        /// Summary description for CustomIndexerInfo
        /// </summary>
        public class EventIndexerInfo : IIndexerInfo
        {
            #region IIndexerInfo Members

            public string Culture
            {
                get { return string.Empty; }
            }

            public Guid ItemID
            {
                get { return Guid.Empty; }
            }

            #endregion

            public string ResolveIndexPath()
            {
                return Path;
            }

            private string _url;
            private Hashtable _metaFields;
            private string _content;

            public EventIndexerInfo(string url, Hashtable metaFields, string content)
            {
                this._url = url;
                this._metaFields = metaFields;
                this._content = content;
            }

            protected string GetMetaData()
            {
                StringBuilder sb = new StringBuilder();
                IDictionaryEnumerator meta = _metaFields.GetEnumerator();

                while (meta.MoveNext())
                {
                    sb.AppendLine();
                    sb.Append("<");
                    sb.Append(meta.Key);
                    sb.Append(">");
                    sb.Append(meta.Value.ToString());
                    sb.Append("</");
                    sb.Append(meta.Key);
                    sb.Append(">");
                }
                return sb.ToString();
            }

            #region IIndexerInfo Members

            public Encoding Encoding
            {
                get { return Encoding.UTF8; }
            }

            public byte[] GetData()
            {
                string text = (string)this._content;

                //If we have any meta data add it to the index content
                if (this._metaFields.Count > 0)
                {
                    text += this.GetMetaData();
                }

                return this.Encoding.GetBytes(text);
            }

            public string MimeType
            {
                get { return "text/html"; }
            }

            public string Path
            {
                get { return this._url; }
            }

            #endregion
        }
    }

    //EventIndexProvider.cs

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using Telerik.Framework.Search;
    using Telerik.Cms.Engine;
    using Telerik.Events;
    using System.Configuration;

    namespace EventIndex
    {
        /// <summary>
        /// Summary description for CustomIndexProvider
        /// </summary>
        public class EventIndexProvider : IIndexingServiceClient
        {
            /// <summary>
            /// Defines the name of the provider. This name is used to mange providers within Indexing Service.
            /// </summary>
            public string Name
            {
                get
                {
                    return "EventIndexProvider";
                }
            }

            /// <summary>
            /// Provides detailed description of the client
            /// </summary>
            public string Description
            {
                get
                {
                    return "Provides indexing for events.";
                }
            }

            /// <summary>
            /// Meta fields for this provider
            /// </summary>
            protected string[] MetaFields
            {
                get
                {
                    return new string[]{
         "Title"
        };
                }
            }

            public IIndexerInfo[] GetContentToIndex()
            {
                // get current events
                EventsManager mgr = new EventsManager("Events");
                IMetaSearchInfo[] filters = new IMetaSearchInfo[2];
                filters[0] = new MetaSearchInfo(MetaValueTypes.DateTime, "Expiration_Date", DateTime.Now, SearchCondition.GreaterOrEqual);
                filters[1] = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Now, SearchCondition.LessOrEqual);
                IList events = mgr.Content.GetContent("Event_Start ASC", filters);

                List<IIndexerInfo> list = new List<IIndexerInfo>();

                string urlRequest = "http://" + System.Web.HttpContext.Current.Request.Url.Host;

                foreach (IContent ev in events)
                {
                    Hashtable metaFields = new Hashtable();
                    foreach (string key in MetaFields)
                    {
                        metaFields.Add(key, "");
                    }

                    metaFields["Title"] = ev.GetMetaData("Title");

                    list.Add(
                        new EventIndexerInfo(
                            urlRequest + ConfigurationManager.AppSettings["EventsDetailsPath"].ToString() + ev.UrlWithExtension,
                        metaFields,
                        ev.Content.ToString())
                        );
                }

                return list.ToArray();
            }

            public string[] GetUrlsToIndex()
            {
                // You must use FULL URLs
                var urls = new string[]
                    {
                        "[url]/news-details-page.aspx"
                    };

                return urls;
            }

            public event EventHandler<IndexEventArgs> Index;

            public void Initialize(System.Collections.Generic.IDictionary<string, string> settings)
            {
            }
        }
    }

    //SettingsControl.cs

    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Web.UI;
    using Telerik.Framework.Search;

    namespace EventIndex
    {
        public class SettingsControl : CompositeControl, ISettingsControl
        {
            #region Properties

            public string ControlTemplatePath
            {
                get
                {
                    object o = this.ViewState["ControlTemplatePath"];
                    //if (o == null)
                    //    return "~/home/event-details-page.aspx";
                    return (string)o;
                }
                set
                {
                    this.ViewState["ControlTemplatePath"] = value;
                }
            }

            public IDictionary<string, string> GetSettings()
            {
                this.settings = new Dictionary<string, string>();
                return this.settings;
            }

            #endregion

            #region Methods

            protected override void CreateChildControls()
            {
                this.ctrlContainer = new Container(this);
                this.controlTemplate = new DefaultTemplate(this.settings);
                this.controlTemplate.InstantiateIn(this.ctrlContainer);
                this.Controls.Add(this.ctrlContainer);
            }

            public void InitSettings(IDictionary<string, string> settings)
            {
                this.settings = settings;
            }

            #endregion

            #region Default Template

            protected class DefaultTemplate : ITemplate
            {
                public DefaultTemplate(IDictionary<string, string> settings)
                {
                    this.settings = settings;
                }

                public void InstantiateIn(Control container)
                {
                }

                private IDictionary<string, string> settings;
            }

            #endregion

            #region Container

            protected class Container : GenericContainer<SettingsControl>
            {
                public Container(SettingsControl owner)
                    : base
                    (owner)
                {
                }
            }

            #endregion

            #region Private Fields

            private IDictionary<string, string> settings;
            private Container ctrlContainer;
            private ITemplate controlTemplate;

            #endregion
        }
    }


    //ViewControl.cs

    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Web.UI;
    using Telerik.Framework.Search;
    using Telerik.Framework.Web;

    namespace EventIndex
    {
        public class ViewControl : CompositeControl, ISearchViewControl
        {
            #region Properties

            public string TemplatePath
            {
                get
                {
                    object o = this.ViewState["TemplatePath"];
                    //if (o == null)
                    //    return "~/home/event-details-page.aspx";
                    return (string)o;
                }
                set
                {
                    this.ViewState["TemplatePath"] = value;
                }
            }

            public ITemplate ItemTemplate
            {
                get
                {
                    if (this.itemTemplate == null)
                        this.itemTemplate = ControlUtils.GetTemplate<DefaultTemplate>(this.TemplatePath);
                    return this.itemTemplate;
                }
            }

            #endregion

            #region Methods

            protected override void CreateChildControls()
            {
                this.container = new ControlContainer(this);
                this.ItemTemplate.InstantiateIn(this.container);
                this.Controls.Add(this.container);
            }

            #endregion

            #region Private Fields

            private ControlContainer container;
            private ITemplate itemTemplate;
            private IDictionary<string, string> settings;

            #endregion

            #region Default Template

            protected class DefaultTemplate : ITemplate
            {
                public void InstantiateIn(Control container)
                {
                }
            }

            #endregion

            #region Container

            protected class ControlContainer : GenericContainer<ViewControl>
            {
                public ControlContainer(ViewControl owner)
                    : base(owner)
                {
                }
            }

            #endregion

            #region ISearchViewControl Members

            public void InitializeSettings(IDictionary<string, string> settings)
            {
                this.settings = settings;
            }

            #endregion
        }
    }



    //web.config

    <indexClients>       
    <add name="EventIndex" type="EventIndex.EventIndexProvider, App_Code" settingsControl="EventIndex.SettingsControl" viewSettingsControl="EventIndex.ViewControl" description="Provides indexing for events." />
    <add name="PageIndex" type="Telerik.Cms.Search.PageIndexProvider, Telerik.Cms" settingsControl="Telerik.Cms.Web.UI.PageIndexSettings, Telerik.Cms" viewSettingsControl="Telerik.Cms.Web.UI.SearchViewControl, Telerik.Cms" description="Provides indexing services for CMS Pages."/>
    </indexClients>


    Please tell where i am wrong?

    Thanks
    G.GopalRaman

  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Apr 2010
    Link to this post
    Hi gopalraman gopal,

    I the code sent, when I run the indexer I get a null reference exception in the following statement in the EventIndexProvider.cs file:
    list.Add(
        new EventIndexerInfo(
            urlRequest + ConfigurationManager.AppSettings["EventsDetailsPath"].ToString() + ev.UrlWithExtension,
        metaFields,
        ev.Content.ToString())
        );

    The null value is coming from this ConfigurationManager.AppSettings["EventsDetailsPath"]. The reason for this is because the web.config file does not contain a key EventsDetailsPath in the appSettings configuration section. If you have the code from somewhere, please check if there is any mentioning that you should put something in <appSettings> in web.config.

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. gopalraman gopal
    gopalraman gopal avatar
    52 posts
    Registered:
    03 Dec 2009
    28 Apr 2010
    Link to this post
    Hi Radoslav Georgiev

    Thanks to check my code. I already added "EventsDetailsPath" in web.config  file inside

    appSettings tag

     

    <

     

    add key="EventsDetailsPath" value="/home/event-details-page" />


    Thanks
    G.GopalRaman

     

  8. gopalraman gopal
    gopalraman gopal avatar
    52 posts
    Registered:
    03 Dec 2009
    29 Apr 2010
    Link to this post
    hi

    After indexing in Table "sf_Search_IndexignClient" it is added like this.

    Application                            /
    ClientID                                bead4199-b462-44aa-8781-279d236178aa
    Name                                   EventIndex 
    Description                            Null
    ClientTypeName                    Null
    SettingsControl                    EventIndex.SettingsControl,
                                                App_Code.aybrfvov,Version=0.0.0.0, 
                                            Culture=neutral,PublicKeyToken=null
    ViewSettingsControl            Null
    ParentID                            e9228993-6704-4b3b-bc63-03106b57f8f0


    Is this correct?

    Thanks
    G.GopalRaman
  9. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    29 Apr 2010
    Link to this post
    Hello gopalraman gopal,

    Yes this is correct. The more important thing is what is in the Search Index itself. You can take a look at this webinar explaining how to check the data in your search index using Lucene Luke.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. Nic
    Nic avatar
    5 posts
    Registered:
    22 Mar 2011
    16 Dec 2011
    Link to this post
    Hi,

    I'm having a similar problem. I am working with Sitefinity 3.6 and created an index. I noticed not all pages were being indexed and found in the log file that there seemed to be an issue with a master page I created. In C# I was attempted to get a session variable and had the following

    string tempString = "";
    if (Session["mySession"] != null)
             tempString = Session["mySession"].ToString();

    This was causing me to get:
    Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.

    I updated my web.config to look like this:

    <httpModules>
       <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
       <add name="Cms" type="Telerik.Cms.Web.CmsHttpModule, Telerik.Cms"/>
       <!-- Http Module for extension mappings in Library module.-->
       <!--<add name="LibraryModule" type="Telerik.Libraries.LibraryHttpModule, Telerik.Libraries"/>-->
       <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule, Telerik.Web.UI"/>
       <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
      </httpModules>
    <pages enableSessionState="true">
       <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/>
        <add tagPrefix="telerik" namespace="Telerik.Charting" assembly="Telerik.Web.UI"/>
        <add tagPrefix="telerik" namespace="Telerik.Cms.Web.UI" assembly="Telerik.Cms.Web.UI"/>
        <add tagPrefix="telerik" namespace="Telerik.Cms.Web.UI" assembly="Telerik.Framework"/>
       </controls>
      </pages>

    And I even updated my Session start funcation in the Global.asax to look like this:

    protected void Session_Start(Object sender, EventArgs e)
        {
            Application.Lock();
            Application["noOfUsers"] = (int)Application["noOfUsers"] + 1;
      Session["mySession"] = "False";
            Application.UnLock();
        }

    What in the world am I missing to get rid of this error and get my indexing to work?
    Thanks in advance for your help!
    Nic
Register for webinar
10 posts, 0 answered