PDA

View Full Version : Meta tags


QBall777
08-21-2009, 05:12 PM
Hi

I'm attempting to add meta tags dynamically from my sql db.
On the master.page I get the data using an <asp:sqlDataSource>

But in the code behind I'm unsure how to apply this.

htmMeta.Attributes.Add("content", "'<%# MetaTitle %>'");


//Find the Head Tag in Master Page
HtmlHead hdMain = (HtmlHead)Page.Master.FindControl("mainHead");
HtmlMeta htmMeta = new HtmlMeta();
htmMeta.Attributes.Add("name","description");
htmMeta.Attributes.Add("content", "'<%# MetaTitle %>'");
//Add Meta Tag to Head

hdMain.Controls.Add(htmMeta);
//Adding keyword Meta Tag to Head Section
HtmlMeta hm2 = new HtmlMeta();
hm2.Attributes.Add("name", "keywords");
hm2.Attributes.Add("content", "Here you can pass your keywords");
hdMain.Controls.Add(hm2);

Hope someone can help.

Thanks

HostingASPNet
08-23-2009, 06:30 AM
Hello,

No, you could not use <%# MetaTitle %> in the code behind page. You could find some ASP.NET SQL Server examples here - http://www.asp.net/LEARN/sql-videos/

Regards

ghell
09-08-2009, 06:51 PM
If it is on the master page anyway, you may be able to just use <%# ... %> inside your <meta ...> in something like a repeater control. I don't know how well this would work since it's in the html header so probably outside of the asp.net form.

Other than that it would be just opening the SQL connection, executing the command to get a reader and looping through the results adding the meta tags as you go.


To be honest, I find all of these html meta tags almost completely useless. For example, modern search engines parse your content rather than look at your meta keywords.