Dynamic Meta Description content
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.
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);
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.
I can confirm that above solution work fine from MVC feather widgets.