Default Meta Keywords & Description

Posted by Community Admin on 03-Aug-2018 19:03

Default Meta Keywords & Description

All Replies

Posted by Community Admin on 12-Jul-2011 00:00

Is there a way to set default meta Keywords & Description that will be used if no description and/or keywords is entered in the Title & Properties for an individual page?

Posted by Community Admin on 13-Jul-2011 00:00

Hello,

You can try to set them at runtime in case the values are empty. You'll need to create a class that inherits from

SitefinityPageResolver and inside you should override the SetPageDirectives method. PLease find below its default implementation that concerns you:

this.AddPageDirectiveValue(pageAttribs, "MetaDescription", "your description");
this.AddPageDirectiveValue(pageAttribs, "MetaKeywords", "your");

SetPageDirectives accepts two parameters PageData pageData and DirectiveCollection directives. Form the pageData you can check whether the default value for Keywords/Description is empty string.

Regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 29-Sep-2011 00:00

Hi, I'm also interested in overriding the SitefinityPageResolver in this way, and I have two questions as a follow up to this:

1. AddPageDirectiveValue() needs a NameValueCollection as the first parameter; is this supposed to come from pageData.Attributes? pageData.Attributes is actually of type IDictionary, so would I need to first convert this to a NameValueCollection type?

2. Once I create a class to override the SitefinityPageResolver, do I need to register my class somewhere in order for it to be used within Sitefinity? For instance, somewhere in the configuration->advanced menu?


Posted by Community Admin on 30-Sep-2011 00:00

Hello Christina,

Here is a sample that shows how to use the pageattributes

var pageAttribs = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
pageAttribs["Language"] = "C#";
this.AddPageDirectiveValue(pageAttribs, "EnableViewState", pageData.EnableViewState, true);

The class should be registered through IoC and our ObjectFactory class using RegisterType method of UnityContainerExtensions inside Global.asax - Application_Start.

Kind regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 30-Sep-2011 00:00

Thanks for the guidance. I'm still a little bit stumped as far as correctly registering my custom class with Sitefinity.

The following code produces causes the error "The type String cannot be constructed. You must configure the container to supply this value" to occur upon load of every page, and the SetPageDirectives() in my CustomPageResolver class is never called.

        protected void Application_Start(object sender, EventArgs e)
        
	    ObjectFactory.Container.RegisterType<SitefinityPageResolverCustomPageResolver>();
        

I also tried registering this inside of Bootstrapper_Initialized. This results in no errors, but the SetPageDirectives() in my CustomPageResolver class is still never called.

        protected void Application_Start(object sender, EventArgs e)
        
            Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized += Bootstrapper_Initialized;
        

        protected void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs args)
        
	    ObjectFactory.Container.RegisterType<SitefinityPageResolverCustomPageResolver>();
        

This is my CustomPageResolver:

    public class CustomPageResolver : SitefinityPageResolver 
    
        protected override void SetPageDirectives(PageData pageData, DirectiveCollection directives)
        
            base.SetPageDirectives(pageData, directives);
 
            var pageAttribs = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
            pageAttribs["Language"] = "C#";
            this.AddPageDirectiveValue(pageAttribs, "MetaDescription""your description");
            this.AddPageDirectiveValue(pageAttribs, "MetaKeywords""your keywords");
        
    


Am I missing something obvious? Thanks!!

Posted by Community Admin on 03-Oct-2011 00:00

Hi Christina,

Try to register the custom page resolver as shown below

           ObjectFactory.Container.RegisterType<IVirtualFileResolver, SitefinityPageResolverCustom>("PageResolver",

            new ContainerControlledLifetimeManager(), new InjectionConstructor());



Greetings,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 03-Oct-2011 00:00

OK. I am now doing this to register my type. However, I am still getting the same error message (as follows). Any idea why this might be occurring?

protected void Application_Start(object sender, EventArgs e)
            ObjectFactory.Container.RegisterType<IVirtualFileResolver, CustomPageResolver>(
                "PageResolver",
                new ContainerControlledLifetimeManager(),
                new InjectionConstructor()
            );


Server Error in '/' Application.

The type String cannot be constructed. You must configure the container to supply this value.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type String cannot be constructed. You must configure the container to supply this value.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The type String cannot be constructed. You must configure the container to supply this value.]
   Telerik.Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) +161
   Telerik.Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) +136
   Telerik.Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +190
   Telerik.Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) +108
   Telerik.Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +137
   Telerik.Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +190
   Telerik.Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +113
   Telerik.Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +48
   BuildUp_Telerik.Sitefinity.Configuration.ConfigManager(IBuilderContext ) +113
   Telerik.Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +12
   Telerik.Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +195
   Telerik.Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +190
   Telerik.Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +163

[ResolutionFailedException: Resolution of the dependency failed, type = "Telerik.Sitefinity.Configuration.ConfigManager", name = "XmlConfigProvider".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type String cannot be constructed. You must configure the container to supply this value.
-----------------------------------------------
At the time of the exception, the container was:

  Resolving Telerik.Sitefinity.Configuration.ConfigManager,XmlConfigProvider
  Resolving parameter "providerName" of constructor Telerik.Sitefinity.Configuration.ConfigManager(System.String providerName)
    Resolving System.String,(none)
]
   Telerik.Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +327
   Telerik.Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) +15
   Telerik.Microsoft.Practices.Unity.UnityContainerExtensions.Resolve(IUnityContainer container, String name, ResolverOverride[] overrides) +82
   Telerik.Sitefinity.Abstractions.ObjectFactory.Resolve(String name) +74
   Telerik.Sitefinity.Data.ManagerBase`1.GetManager(String providerName, String transactionName) +255
   Telerik.Sitefinity.Services.InstallContext..ctor(String transactionName) +54
   Telerik.Sitefinity.Services.SystemManager.Initialize() +197
   Telerik.Sitefinity.Abstractions.Bootstrapper.RegisterRoutes(RouteCollection routes) +278
   Telerik.Sitefinity.Abstractions.Bootstrapper.Bootstrap() +236
   Telerik.Sitefinity.Web.SitefinityHttpModule.Init(HttpApplication context) +115
   System.Web.Routing.UrlRoutingModule.System.Web.IHttpModule.Init(HttpApplication application) +10
   System.Web.HttpApplication.InitModulesCommon() +172
   System.Web.HttpApplication.InitModules() +43
   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +828
   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +304
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +327


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237              

Posted by Community Admin on 29-Oct-2012 00:00

Hello,

Any update on this?  I tried the same code as mentioned and the custom Page Resolver logic is never invoked.  I did run my project through the debugger and the Object Factory Registration does happen but my custom logic is never executed.

Thanks,
Thomas

This thread is closed