开发者

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="descr开发者_StackOverflow社区iption" 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!


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).


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜