Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Registering a custom content provider

Vote:
 

Hello all, 

I am trying to add an example content provider, https://github.com/episerver/YouTubeContentProvider, and have added it to my local solution. I am now trying to register the content provider and have added the following to my web.config.

 

The YouTubeProvider class has the following structure:

namespace EPiServer.Sample.YouTubeProvider
{
    ///
    public class YouTubeProvider : ContentProvider
    {
        #region Fields

        private readonly ServiceAccessor

#246715
Jan 13, 2021 0:07
Vote:
 

My original post got truncated. My issue is that when I add a registration for a content provider in the web.config, the site produces an error that it can't load the provider type. I have created a blank class and tried to register that with the same results. Any suggestions on what I may be missing?

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Provider type 'Org.Business.TestProvider, Org.Business' could not be loaded.

Source Error:

Line 406:    
#246716
Jan 13, 2021 1:00
Vote:
 

Hi Raquel,

Have you included the 'Episerver,Sample.YouTubeProvider' project in your local solution and it's rebuilding successfully?

#246745
Jan 13, 2021 16:28
Vote:
 

Have you registered your content provider, something like this (in an initialization module)

        private static void InitializeContentProvider(InitializationEngine context)
        {
            var providerManager = context.Locate.Advanced.GetInstance

#246820
Jan 14, 2021 10:43
Quan Mai - Jan 14, 2021 13:20
private static void InitializeContentProvider(InitializationEngine context)
{
var providerManager = context.Locate.Advanced.GetInstance
Vote:
 

        private static void InitializeContentProvider(InitializationEngine context)
        {
            var providerManager = context.Locate.Advanced.GetInstance<IContentProviderManager>();
            var catalogProvider = context.Locate.Advanced.GetInstance<CatalogContentProvider>();
            var settings = new NameValueCollection
            {
                {ContentProviderElement.EntryPointString, 0.ToString()}
            };
            catalogProvider.Initialize(CatalogContentProvider.DefaultProviderKey, settings);
            providerManager.ProviderMap.AddProvider(catalogProvider);
        }

#246831
Jan 14, 2021 13:23
Vote:
 

I agree with Quan post for more help you can try below example:

    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class YouTubeProviderInitializer : IInitializableModule
    {
        public void Initialize(Framework.Initialization.InitializationEngine context)
        {
			// Create provider root if not exists
			var contentRepository = context.Locate.ContentRepository();
			var youTubeRoot = contentRepository.GetBySegment(SiteDefinition.Current.RootPage, YouTubeSettings.ProviderName, LanguageSelector.AutoDetect(true));
			if (youTubeRoot == null)
			{
				youTubeRoot = contentRepository.GetDefault<ContentFolder>(SiteDefinition.Current.RootPage);
				youTubeRoot.Name = YouTubeSettings.ProviderName;
				contentRepository.Save(youTubeRoot, SaveAction.Publish, AccessLevel.NoAccess);
			}

                        // Register provider
			var contentProviderManager = context.Locate.Advanced.GetInstance<IContentProviderManager>();
			var configValues = new NameValueCollection { {ContentProviderElement.EntryPointString, youTubeRoot.ContentLink.ToString()} };
	                var provider = context.Locate.Advanced.GetInstance<YouTubeProvider>();
			provider.Initialize(YouTubeSettings.ProviderKey, configValues);
			contentProviderManager.ProviderMap.AddProvider(provider);
	}
   }
#246838
Jan 14, 2021 15:32
Vote:
 

Thanks for the replies. 

The content provider has registered now when I added the code in the initialization module. 

To clarify, there are 2 ways to do this, right? So either add via the initialization module or web.config? 

I currently have both in place. 

#246873
Jan 15, 2021 4:45
Vote:
 

Thanks @Sanjay Kumar and @Quan Mai. Can't find the tick mark to mark your reply as the answers but your response helped me, much appreciated! 

#247830
Jan 28, 2021 22:42
Quan Mai - Jan 29, 2021 9:12
I marked the posts as answer. Glad to hear it helped
Sanjay Kumar - Jan 29, 2021 9:38
Thanks Quan :)
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.