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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.