Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Mitchell 35 posts 60 karma points
    Jul 18, 2011 @ 01:49
    Mark Mitchell
    0

    Multiple title tags in the HTML head area

    I noticed that my pages were throwing HTML Validation error because the head contained two title tags. The first one was created by the Razor macro, uBlogsyBrowserTitle.cshtml, and then there was another blank one at the very end of the head section.

    After experimenting it looks like ASP.Net is automatically creating the second blank one because it apparently never see the one created by Razor (perhaps it is added too late in the process).  If you have a title tag defined in the masterpage though, the second one will not be generated.

    I fixed the problem by removing the actual title tag from the Razor macro and then adding a title tag in the template, with the razor macro nested inside of it.

    Here is the updated code in the uBlogsyBaseSite template:

        <%-- get title for browser --%>
        <title><umbraco:Macro ID="Macro1" runat="server" Language="razor" Alias="uBlogsyBrowserTitle" /></title>

     

    Here is the updated uBlogsyBrowserTitle.cshtml :

    @{
    // get title of page
    var landing = Model.AncestorOrSelf(1).DescendantsOrSelf("uBlogsyLanding").First();
    string title = landing.uBlogsyContentTitle;
    if (Model.Id != landing.Id){
    title += " : " + Model.uBlogsyContentTitle;
    }
    @title
    }
  • martin uhe 7 posts 27 karma points
    Jul 18, 2011 @ 04:41
    martin uhe
    0

    Thats very interesting, I was unaware that the masterpages generated HTML tags before. Would you be so kind to show your original code, as I tested a masterpage without a title tag (Umbraco 4.5, .NET 3.5) and it did not generate a tag. I don't suspect that there should be any differences and that the issue is in-fact due to the original razor macro. If the behaviour does in-fact exist in Umbraco 4.7 then I would be very keen to investigate as I am currently planning an upgrade for a quite high traffic site and this behaviour could cause quite a few issues for me. Thanks in advance.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 18, 2011 @ 10:42
    Kim Andersen
    1

    Hi guys.

    I haven't seen the code in your masterpage, but I guess that there's a runat="server" attibute on the head-tag. If this is the case, this is also the reason why there's generated an empty title-tag. What will happen is, that the runat="server" creates a title-tag if there's not already one present in the masterpage.

    I don't know why this happens (haven't researched on this yet :) ), but I've noticed it before because I needed he runat="server" on the head-tag in one of my projects to make the RegisterStylesheet-extension work properly.

    /Kim A

  • Mark Mitchell 35 posts 60 karma points
    Jul 18, 2011 @ 14:43
    Mark Mitchell
    0

    Hi Martin,

    Here is my masterpage before I changed the macro up to the end of the head section:

    <%@ Master Language="C#" MasterPageFile="~/masterpages/uBlogsyBase.master" AutoEventWireup="true" %>

    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head id="Head1" runat="server">
        <%-- get title for browser --%>
        <umbraco:Macro ID="Macro1" runat="server" Language="razor" Alias="uBlogsyBrowserTitle" />
        <%-- get meta title and description --%>
        <umbraco:Macro ID="Macro5" runat="server" Alias="uBlogsySeoMeta" />
       
        <link href="/css/styles.css" rel="stylesheet" type="text/css" />
        <!--[if lt IE 8]>
        <link href="/css/IE7.css" rel="stylesheet" type="text/css" />
        <![endif]-->
        <link type="text/css" rel="Stylesheet" media="screen" href="/css/bvt-blog.css" />
            
        <!-- jQuery Library + ALL jQuery Tools -->
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
        <script type="text/javascript" src="http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js"></script>  
        
        <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>  
          
        <!-- Google Analytics Code Start -->
        <!--<script type="text/javascript">
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-15678458-1']);
          _gaq.push(['_trackPageview']);
          (function () {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();
        </script> -->
        <!-- Google Analytics Code Start -->
      </head>

     

    It woud make sense that this is also due to the runat="server" as Kim pointed out. This additional parameter allows asp.net to manipulate code in the head section, which can be pretty handy in a lot of scenarios. If you change the macro and template as I described in the first post though, then the title tag will not be an issue either way.

    Mark

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jul 19, 2011 @ 10:17
    Anthony Dang
    0

    Which version of uBlogsy are you using?

     

  • martin uhe 7 posts 27 karma points
    Jul 20, 2011 @ 06:26
    martin uhe
    0

    Yeah just as Kim stated, heres your culprit.

    <headid="Head1"runat="server">

    You have a runat="server" in your head-tag and from what you has stated you have already fixed the issue. Personally I have never had any real reason to manipulate code in the head section as i use a content place holder inside the head for page specific content in conjunction with ClientDependancy.

    <asp:ContentPlaceHolder ID="MasterHeadPlaceHolder" runat="server"></asp:ContentPlaceHolder>

    Also please comment out your Google Analytics account Id to something like:

    _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);

    I'm sure there aren't too many nasty people browing thru these forums but I would hate someone to do something malicous with it.

  • Mark Mitchell 35 posts 60 karma points
    Jul 20, 2011 @ 06:40
    Mark Mitchell
    0

    Hi Martin,

    It looks like the forum will not let me edit the account ID in the post. I just tried to edit the post but the forum editor truncates most of the code in the including all of the google analytics section. Must be a glitch in the sanitation / parsing of the forum editor.

    I am not too worried about it though. I had almost edited it out when I originally posted it, but then decided not to since it is very easily obtained anyway. All one needs to do to get the analytics ID for any site that uses one is to just view the HTML source of the website from the browser. The same code is right there for anyone to grab if they were looking for it.

    I do appreciate the concern though! :)

Please Sign in or register to post replies

Write your reply to:

Draft