views:

83

answers:

2

I have a master page currently with the below for the title:

<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>

I've now realised I have to put meta tags in, would that be best done like so:

<asp:ContentPlaceHolder ID="TitleContent" runat="server">
<title>Title</title>
<meta name="Description" content=" ... add description here ... "> 
<meta name="Keywords" content=" ... add keywords here ... ">
</asp:ContentPlaceHolder>

OR

<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<meta name="Description" content="<asp:ContentPlaceHolder ID="descContent" runat="server" />"> 
<meta name="Keywords" content="<asp:ContentPlaceHolder ID="keysContent" runat="server" />"
+1  A: 

Yes, you could also add page specific meta tags by adding another ContentPlaceHolder for meta tags:

<head>
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    <asp:ContentPlaceHolder ID="MetaTagsContent" runat="server" />
</head>

Then in your non master-page (like index.aspx) you could just

<asp:Content id="MetaTags" ContentPlaceHolderID="MetaTagsContent" runat="server">
    <meta name="Description" content="your content" />
</asp:Content>

This would be much easier, in my opinion, to control the meta tags

BuildStarted
+1  A: 

you don't necessarily have to fill all your views with this stuff, that's why you have a master page. I would do like this:

in Site.master:

<% Html.RenderPartial("meta"); %>

in meta.ascx

    <%
    string controller = ViewContext.RouteData.Values["Controller"];
    string action = ViewContext.RouteData.Values["Action"];
    string content = "default description";
    if(controller == "Home") content = "home specific";
    //or like this
    if(controller == "Home" && action == "Index") content = "bla bla";
//this way you can put the same description for a specific group, you decide
    %>
    <meta name="Description" content='<%=content %>' />
Omu