ASP.NET Line Breaks in Title Element

Posted by Nathan Taylor on Stack Overflow See other posts from Stack Overflow or by Nathan Taylor
Published on 2010-04-29T15:47:54Z Indexed on 2010/04/29 15:57 UTC
Read the original article Hit count: 484

Filed under:
|
|
|
|

I'm trying to optimize SEO readability on our websites and one issue I've come across is ASP.NET butchering the title element of my MasterPage. Entered as such in my MasterPage (manually reformatted to remove line breaks caused by the <% %> tags):

<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /> - <%=WebsiteSettings.WebsiteName %></title>

This is the output I receive:

   <title>
    Home
 - Website Name</title>

As you can see ASP.NET is adding preceding and trailing line breaks where the <asp:ContentPlaceHolder /> is substitute becaused Visual Studio auto-formats <asp:Content /> to start and end with a line break. Obviously, this can be prevented in the Visual Studio formatting options, but this is not ideal because I only would want to remove that behavior for the TitleContent placeholder and not the rest.

Is there any way I can ensure my Title is trimmed before it is rendered? I am using MVC so code-behind is not an acceptable option.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc