I am trying to find a better way to personalize the <head> element of the page to get rid of extra line breaks caused by <head runat="server"> , so it is formatted correctly.
So far, the only thing I've found works:
protected override void Render(HtmlTextWriter writer) { StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter); base.Render(htmlTextWriter); htmlTextWriter.Close(); string html = stringWriter.ToString(); string newHTML = html.Replace("<title>\r\n\t", "<title>") .Replace("\r\n</title>", "</title>") .Replace("</head>", "\n</head>"); writer.Write(newHTML); }
Now I have 2 questions:
- How does the above code affect performance (is it just as viable in a production environment)?
- Is there a better way to do this, for example, a method that I can override only for custom rendering of
<head> ?
Oh yes, ASP.NET MVC is not an option.
EDIT:
I ask about this regarding SEO and just a little bit of perfectionism.
source share