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

Forums / General Discussions / Default Meta Keywords & Description

Default Meta Keywords & Description

8 posts, 0 answered
  1. Seattle Web Group
    Seattle Web Group avatar
    29 posts
    Registered:
    03 May 2011
    12 Jul 2011
    Link to this post
    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?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    13 Jul 2011
    Link to this post
    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
  3. Christina
    Christina avatar
    6 posts
    Registered:
    27 Jul 2011
    29 Sep 2011
    Link to this post
    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?
    
    
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    30 Sep 2011
    Link to this post
    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
  5. Christina
    Christina avatar
    6 posts
    Registered:
    27 Jul 2011
    30 Sep 2011
    Link to this post
    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!!
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    03 Oct 2011
    Link to this post
    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
  7. Christina
    Christina avatar
    6 posts
    Registered:
    27 Jul 2011
    03 Oct 2011
    Link to this post
    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              

  8. Thomas Weidman
    Thomas Weidman avatar
    38 posts
    Registered:
    19 Apr 2004
    29 Oct 2012
    Link to this post
    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
8 posts, 0 answered