Reputation: 13691
I've been trying to figure out the best way to custom render the <head>
element of a page to get rid of the extra line breaks which is caused by <head runat="server">
, so its properly formatted.
So far the only thing i've found which works is the following:
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:
<head>
?Oh yeah ASP.NET MVC is not an option.
EDIT:
Im asking this with regards to SEO and just little bit perfectionism.
Upvotes: 4
Views: 1870
Reputation: 17949
From my experience, using ASP.NET Forms implies an irrevocable surrender of control over your HTML output. It is better to accept the following:
<html>
<head>
and almost always <form>
tags.If you want fine control over your page output, using MVC or another framework is all but mandatory. Even classic ASP will work, but not ASP.NET Forms.
Upvotes: 5