Dynamic Meta Description content

Posted by Community Admin on 04-Aug-2018 04:54

Dynamic Meta Description content

All Replies

Posted by Community Admin on 16-Dec-2014 00:00

Hello All,

Today, I have some of problems when working with <meta> tags in Sitefinity 7.2

I created one widget by MVC and register it to toolbox. And then I created a page, In this page I drag this Widget, so when page open need to set <Meta> content dynamic when page open.

 

Please helps with any solutions.

Best Regards.

 

 

Posted by Community Admin on 18-Dec-2014 00:00

Hi David,

Thank you for contacting us.

The way you can alter the page head in order to add meta tags there for Sitefinity MVC is by accessing the page instance in your MVC controller by calling it through the current handler. The code you should use is something like the following:

HtmlMeta hm = new HtmlMeta();
hm.Attributes.Add("name", "description");
hm.Content = "your meta content";
((System.Web.UI.Page)this.HttpContext.CurrentHandler).Header.Controls.Add(hm);

I hope this helps. Let me know if there is anything else I can do for you.

Regards,
Ivan D. Dimitrov
Telerik
 
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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 20-Jan-2015 00:00

The answer does not work. The CurrentHandler in the controller of a widget is null. So attempting to get the page instance throws a null reference exception. Is there something else that needs to be done? Also, using statements are helpful.

Posted by Community Admin on 08-Jul-2016 00:00

I can confirm that above solution work fine from MVC feather widgets.

This thread is closed