Remo
Remo

Reputation: 389

Is it possible to edit the Meta description from code behind?

In the Master Page for Visual Studio 2005 website, I am using meta description as

<meta name="keywords" content="coupons, coupons, online coupons, health deals, health coupons, computer coupons, bargains, hot bargains" />
<meta name="description" content="<%=MyMetaDescription%>" /> 

I would like to replace the content in each aspx page. How do I use it? I get the same content as description though I have tried to replace the content in code behind page.

In the code behind, i have called Master.MyMetaDescription = "";

Can someone help me out on this. Thanks a lot in advance!

Upvotes: 1

Views: 4977

Answers (3)

Lloyd Powell
Lloyd Powell

Reputation: 18770

I would use this :

 this.Page.MetaKeywords = "football, sport, golf";
 this.Page.MetaDescription = "My site is all about football and golf";

Obviously if you just want to append to them then just use += (don't forget a leading , for the keywords).

Upvotes: 3

VinayC
VinayC

Reputation: 49185

Yuck has already provided a simple enough way to add meta content.

Regardless, see this code project article to see how meta tags can be added from code behind. It also provides a nice solution based on that to easily add meta tags to page.

Upvotes: 0

Yuck
Yuck

Reputation: 50835

Make a content placeholder where the <meta> tag will go in the <head> section:

<html>
  <head>
    <asp:ContentPlaceHolder ID = "MetaContent" runat = "server" />
  </head>

<!-- other content -->

</html>

In your pages then you can replace the content using a different <meta> tag.

<asp:Content ID = "MyMeta" PlaceHolderID = "MetaContent" runat = "server">
  <meta />
</asp:Content>

Upvotes: 1

Related Questions