<title> and <meta> tags - again
<title> and <meta> tags - again
Hello,
Since this is a serious issue for me and it went unanswered last time I would like to ask again.
I, with the help of Judy, worked very hard to get my AC 5.5 ranked very, very well for all of my search terms in Google and Yahoo. If there was a product I carried and I typed some of those words into Google I was always on the first page, most of the time 1, 2 or 3.
When I switched to AC 7 my listings completely disappeared. Judy incorporated the same title and meta information (using custom programming) that was used on my 5.5 site. Google and Yahoo are living on my AC 7 site, daily, but the only listings I can find are ones that are from the 5.5 pages that haven't been re-indexed.
Anyways, for whatever reason I dropped, I still need to find a way to list the <title> and <meta> tags in their traditional way. Look at these tags from the AC 7 demo site, this is just sloppy.
<link href="App_Themes/Glass_SilverAge/ComponentArt.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/print.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/style.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/webparts.css" type="text/css" rel="stylesheet" /><title>
Home Page
</title><style type="text/css">
Everything just runs together. There are no line breaks between tags and why does the title tag display with the title on a separate line with tab spacing in front of it?
I knew I should have waited to after Christmas to go live with the new site. This isn't going to be good.
Can this be fixed? Is it buried in compiled code somewhere?
Since this is a serious issue for me and it went unanswered last time I would like to ask again.
I, with the help of Judy, worked very hard to get my AC 5.5 ranked very, very well for all of my search terms in Google and Yahoo. If there was a product I carried and I typed some of those words into Google I was always on the first page, most of the time 1, 2 or 3.
When I switched to AC 7 my listings completely disappeared. Judy incorporated the same title and meta information (using custom programming) that was used on my 5.5 site. Google and Yahoo are living on my AC 7 site, daily, but the only listings I can find are ones that are from the 5.5 pages that haven't been re-indexed.
Anyways, for whatever reason I dropped, I still need to find a way to list the <title> and <meta> tags in their traditional way. Look at these tags from the AC 7 demo site, this is just sloppy.
<link href="App_Themes/Glass_SilverAge/ComponentArt.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/print.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/style.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/webparts.css" type="text/css" rel="stylesheet" /><title>
Home Page
</title><style type="text/css">
Everything just runs together. There are no line breaks between tags and why does the title tag display with the title on a separate line with tab spacing in front of it?
I knew I should have waited to after Christmas to go live with the new site. This isn't going to be good.
Can this be fixed? Is it buried in compiled code somewhere?
AC 7.0.3 build 13937
Re: <title> and <meta> tags - again
I am not expert on search engine optimization but I see no reason why the tags being output like the above should make any difference to a search engine bot which is a program. Search engine bots are parsing the tags not the lines and in HTML white space (including new line) has no significance.Anyways, for whatever reason I dropped, I still need to find a way to list the <title> and <meta> tags in their traditional way. Look at these tags from the AC 7 demo site, this is just sloppy.
<link href="App_Themes/Glass_SilverAge/ComponentArt.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/print.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/style.css" type="text/css" rel="stylesheet" /><link href="App_Themes/Glass_SilverAge/webparts.css" type="text/css" rel="stylesheet" /><title>
Home Page
</title><style type="text/css">
Everything just runs together. There are no line breaks between tags and why does the title tag display with the title on a separate line with tab spacing in front of it?
There are hundreds of factors affecting search engine ranking. I am sure there are other factors on your new AC7 store affecting your ranking. I am unable to convince myself that absence of line breaks or other 'formatting' could be the reason.... but who knows.
Google's ranking formula is certainly complicated. It might be taking into account your old pages and new pages at the same time ... resulting in a lower score.
Re: <title> and <meta> tags - again
Yes, I know. I have operated a website for over 10 years and trying to figure them out is almost impossible but I did have a good system going.
You are correct. Having duplicate pages from 5.5 to 7.0 most likely got me flushed down the toilet. I have product pages ending in PxxxCxxx.aspx and now the same pages ending only in Pxxx.aspx.
Can't you program something in to make those pages with the Cxxx on the end show up as 404 errors? I was able to get 404 errors just by changing the C to a lowercase c. Then maybe Google can index the site correctly. That is another serious issue (customers who used previous versions of AC)
I wasn't blaming my drop on the meta tags and title layout, but "why not?" have them shown that way? It must be something too difficult because it otherwise just doesn't make any sense. It definitely wouldn't hurt...
Thank you.
You are correct. Having duplicate pages from 5.5 to 7.0 most likely got me flushed down the toilet. I have product pages ending in PxxxCxxx.aspx and now the same pages ending only in Pxxx.aspx.
Can't you program something in to make those pages with the Cxxx on the end show up as 404 errors? I was able to get 404 errors just by changing the C to a lowercase c. Then maybe Google can index the site correctly. That is another serious issue (customers who used previous versions of AC)
I wasn't blaming my drop on the meta tags and title layout, but "why not?" have them shown that way? It must be something too difficult because it otherwise just doesn't make any sense. It definitely wouldn't hurt...
Thank you.
Last edited by draneb on Thu Nov 27, 2008 5:33 am, edited 2 times in total.
AC 7.0.3 build 13937
Re: <title> and <meta> tags - again
I agree. Mazhar will have a look at this and provide a workaround if possible.I wasn't blaming my drop on the meta tags and title layout, but "why not?" have them shown that way? It must be something too difficult because it otherwise just doesn't make any sense. It definitely wouldn't hurt...
What happens is the for the purpose of optimizing the page size, quite often, the rendering code strips out empty spaces from HTML. We will check if that is the case...
Re: <title> and <meta> tags - again
The problem with upgrading your ecom site, especially if your old site is dynamic is that you open up room for duplicate content penalty.
A 404 error will not help you. You need to perform a 301 error, (permanent redirect). Now the problem is that your old site is all dynamic content, and with IIS, you can't do a 301 redirect with no dynamic content.. unless you are using a url re-write program from the get go and can recreate the file/folder structure.
Also, when you update your site so drastically but change the complete code, Google will raise red flags and proceed with caution on your site. It will take a while for everything to get back together.. but it sure is a pain in the a$$
A 404 error will not help you. You need to perform a 301 error, (permanent redirect). Now the problem is that your old site is all dynamic content, and with IIS, you can't do a 301 redirect with no dynamic content.. unless you are using a url re-write program from the get go and can recreate the file/folder structure.
Also, when you update your site so drastically but change the complete code, Google will raise red flags and proceed with caution on your site. It will take a while for everything to get back together.. but it sure is a pain in the a$$
Re: <title> and <meta> tags - again
Thanks Sohaib. That would be great.
Thanks TTMedia. You are right, a 301 redirect would have to be the way to go. So search engines won't remove the page if they keep getting a 404 error?
I have a file on the server that sends me an email with any errors. Slurp and Googlebot are just living on the site, daily, so that is good. I just have to try and get rid of the duplicate content to get back on good terms with them.
Hapy Thanksgiving!
Thanks TTMedia. You are right, a 301 redirect would have to be the way to go. So search engines won't remove the page if they keep getting a 404 error?
I have a file on the server that sends me an email with any errors. Slurp and Googlebot are just living on the site, daily, so that is good. I just have to try and get rid of the duplicate content to get back on good terms with them.

Hapy Thanksgiving!
AC 7.0.3 build 13937
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: <title> and <meta> tags - again
I'm checking on this also. I've done some meta stuff on Draneb's site, but since I'm working full time for Web2Market, I haven't had a lot of time to help him. I remember in some places putting a /n in code to generate a new line.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: <title> and <meta> tags - again
Regarding 301 Redirect Pages
The solution for 301 redirect pages has been already discussed in some threads. Have a look at the following threads
viewtopic.php?f=42&t=7707
viewtopic.php?f=42&t=8004
The solution for 301 redirect pages has been already discussed in some threads. Have a look at the following threads
viewtopic.php?f=42&t=7707
viewtopic.php?f=42&t=8004
Re: <title> and <meta> tags - again
Here is the code to put proper line breaks in the generated HTML. You need to put this method in each page for which you want to have line breaks in the head.
OUT PUT
Code: Select all
protected override void Render(HtmlTextWriter writer)
{
string pageHtml = string.Empty;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
base.Render(hw);
pageHtml = sw.ToString();
int headStartIndex = pageHtml.IndexOf("<head");
int headEndIndex = pageHtml.IndexOf("</head>");
string headerPart = pageHtml.Substring(headStartIndex, ((headEndIndex + 7) - headStartIndex));
StringBuilder sb = new StringBuilder(headerPart);
sb.Replace("<link", "\r<link");
sb.Replace("<META", "\r<META");
sb.Replace("<style", "\r<style");
int sindex = headerPart.IndexOf("<title>");
int eindex = headerPart.IndexOf("</title>");
string titleTag = headerPart.Substring(sindex, (eindex + 8) - sindex);
string titleText = headerPart.Substring((sindex + 7), (eindex - (sindex + 7)));
titleText = titleText.Replace("\r", string.Empty);
titleText = titleText.Replace("\t", string.Empty);
titleText = titleText.Replace("\n", string.Empty);
titleText.Trim();
titleText = String.Format("\r<title>{0}</title>", titleText);
sb.Replace(titleTag, titleText);
sb.Replace("</head>", "\r</head>");
string newHeaderPart = sb.ToString();
pageHtml = pageHtml.Replace(headerPart, newHeaderPart);
hw.Close();
}
sw.Close();
}
writer.Write(pageHtml);
}
<link href="App_Themes/AbleCommerce/ComponentArt.css" type="text/css" rel="stylesheet" />
<link href="App_Themes/AbleCommerce/Gallery.css" type="text/css" rel="stylesheet" />
<link href="App_Themes/AbleCommerce/print.css" type="text/css" rel="stylesheet" />
<link href="App_Themes/AbleCommerce/style.css" type="text/css" rel="stylesheet" />
<link href="App_Themes/AbleCommerce/webparts.css" type="text/css" rel="stylesheet" />
<title>Home Page</title>
<style type="text/css">
.ctl00_wpm_HomePage_ctl02_CategoryTree_0 { text-decoration:none; }
.ctl00_ContentZone_0 { border-color:Black;border-width:1px;border-style:Solid; }
</style>
</head>
Re: <title> and <meta> tags - again
Thank you Mazhar!
Thank you Sohaib!
You are awesome. It works great.
Thank you Sohaib!
You are awesome. It works great.
AC 7.0.3 build 13937
Re: <title> and <meta> tags - again
Mazhar, I put the code in my Product.aspx file and the tags were displaying great.
Just testing around, as I quite often do, I found that if I click on my Write a Review link I get redirected to my custom 404 error page. If I take the code out I can click on the Write a Review link and get the form without any problems.
Would you happen to be able to verify this on yours?
Thank you.
Just testing around, as I quite often do, I found that if I click on my Write a Review link I get redirected to my custom 404 error page. If I take the code out I can click on the Write a Review link and get the form without any problems.
Would you happen to be able to verify this on yours?
Thank you.
AC 7.0.3 build 13937
Re: <title> and <meta> tags - again
let me check
Re: <title> and <meta> tags - again
I think this problem is due to ajax call. We need to make sure that if the response html contains head tag then we need to adjust it otherwise do nothing. Try the following updated code
Code: Select all
protected override void Render(HtmlTextWriter writer)
{
string pageHtml = string.Empty;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
base.Render(hw);
pageHtml = sw.ToString();
if (pageHtml.Contains("<head") && pageHtml.Contains("</head>"))
{
int headStartIndex = pageHtml.IndexOf("<head");
int headEndIndex = pageHtml.IndexOf("</head>");
string headerPart = pageHtml.Substring(headStartIndex, ((headEndIndex + 7) - headStartIndex));
StringBuilder sb = new StringBuilder(headerPart);
sb.Replace("<link", "\r<link");
sb.Replace("<META", "\r<META");
sb.Replace("<style", "\r<style");
int sindex = headerPart.IndexOf("<title>");
int eindex = headerPart.IndexOf("</title>");
string titleTag = headerPart.Substring(sindex, (eindex + 8) - sindex);
string titleText = headerPart.Substring((sindex + 7), (eindex - (sindex + 7)));
titleText = titleText.Replace("\r", string.Empty);
titleText = titleText.Replace("\t", string.Empty);
titleText = titleText.Replace("\n", string.Empty);
titleText.Trim();
titleText = String.Format("\r<title>{0}</title>", titleText);
sb.Replace(titleTag, titleText);
sb.Replace("</head>", "\r</head>");
string newHeaderPart = sb.ToString();
pageHtml = pageHtml.Replace(headerPart, newHeaderPart);
}
hw.Close();
}
sw.Close();
}
writer.Write(pageHtml);
}
Re: <title> and <meta> tags - again
Hi Mazhar,
That code worked. Thank you very much.
That code worked. Thank you very much.
AC 7.0.3 build 13937
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: <title> and <meta> tags - again
One more tweak would be nice:
Render the <title> tags before the other <meta> tags. SEO software complains that it should be first. I've experimented some, but other things in the page code seem to override what line I put the Page.Title on.
Render the <title> tags before the other <meta> tags. SEO software complains that it should be first. I've experimented some, but other things in the page code seem to override what line I put the Page.Title on.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: <title> and <meta> tags - again
I think it could be done by interchanging the title tag with first meta tag.One more tweak would be nice:
Render the <title> tags before the other <meta> tags. SEO software complains that it should be first. I've experimented some, but other things in the page code seem to override what line I put the Page.Title on.
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: <title> and <meta> tags - again
I've tried moving it up above the meta tags in the above code and it didn't change. I'll try again.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: <title> and <meta> tags - again
Is there a way this could be put into the pagehelper.cs? I tried it and got an error
CS0115: 'PageHelper.Render(System.Web.UI.HtmlTextWriter)': no suitable method found to override
CS0115: 'PageHelper.Render(System.Web.UI.HtmlTextWriter)': no suitable method found to override
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: <title> and <meta> tags - again
From interchange i mean that we need to interchange the meta tags and tittle tag information in available page HTML string not by interchanging code statements. I have tried to put this functionality as well, the newly added code contains the comments to describe the purpose of statements. Please try the codeI've tried moving it up above the meta tags in the above code and it didn't change. I'll try again.
Code: Select all
protected override void Render(HtmlTextWriter writer)
{
string pageHtml = string.Empty;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
base.Render(hw);
pageHtml = sw.ToString();
if (pageHtml.Contains("<head") && pageHtml.Contains("</head>"))
{
int headStartIndex = pageHtml.IndexOf("<head");
int headEndIndex = pageHtml.IndexOf("</head>");
string headerPart = pageHtml.Substring(headStartIndex, ((headEndIndex + 7) - headStartIndex));
StringBuilder sb = new StringBuilder(headerPart);
sb.Replace("<link", "\r<link");
sb.Replace("<META", "\r<META");
sb.Replace("<style", "\r<style");
int sindex = headerPart.IndexOf("<title>");
int eindex = headerPart.IndexOf("</title>");
string titleTag = headerPart.Substring(sindex, (eindex + 8) - sindex);
string titleText = headerPart.Substring((sindex + 7), (eindex - (sindex + 7)));
titleText = titleText.Replace("\r", string.Empty);
titleText = titleText.Replace("\t", string.Empty);
titleText = titleText.Replace("\n", string.Empty);
titleText.Trim();
titleText = String.Format("\r<title>{0}</title>", titleText);
sb.Replace(titleTag, titleText);
sb.Replace("</head>", "\r</head>");
string newHeaderPart = sb.ToString();
//find out the index of first meta tag
int metaIndex = newHeaderPart.IndexOf("<META", StringComparison.CurrentCultureIgnoreCase);
//meta tag found
if (metaIndex >= 0)
{
//remove the current title information
newHeaderPart.Replace(titleText, string.Empty);
//inject the title information at first meta tag index
newHeaderPart = newHeaderPart.Insert(metaIndex, titleText);
}
pageHtml = pageHtml.Replace(headerPart, newHeaderPart);
}
hw.Close();
}
sw.Close();
}
writer.Write(pageHtml);
}
Re: <title> and <meta> tags - again
You can not move the complete Render method inside the PageHelper. Its something specific to the ASPX Page. I am overriding the ASPX default rendering by providing an overridden version of Render method in each page. A part of method could be moved inside the PageHelperbut still you will need it in each page.Is there a way this could be put into the pagehelper.cs? I tried it and got an error
CS0115: 'PageHelper.Render(System.Web.UI.HtmlTextWriter)': no suitable method found to override
For example in PageHelper you can create the following function.
Code: Select all
public static void AdjustHTML(ref string pageHtml)
{
if (pageHtml.Contains("<head") && pageHtml.Contains("</head>"))
{
int headStartIndex = pageHtml.IndexOf("<head");
int headEndIndex = pageHtml.IndexOf("</head>");
string headerPart = pageHtml.Substring(headStartIndex, ((headEndIndex + 7) - headStartIndex));
StringBuilder sb = new StringBuilder(headerPart);
sb.Replace("<link", "\r<link");
sb.Replace("<META", "\r<META");
sb.Replace("<style", "\r<style");
int sindex = headerPart.IndexOf("<title>");
int eindex = headerPart.IndexOf("</title>");
string titleTag = headerPart.Substring(sindex, (eindex + 8) - sindex);
string titleText = headerPart.Substring((sindex + 7), (eindex - (sindex + 7)));
titleText = titleText.Replace("\r", string.Empty);
titleText = titleText.Replace("\t", string.Empty);
titleText = titleText.Replace("\n", string.Empty);
titleText.Trim();
titleText = String.Format("\r<title>{0}</title>", titleText);
sb.Replace(titleTag, titleText);
sb.Replace("</head>", "\r</head>");
string newHeaderPart = sb.ToString();
//find out the index of first meta tag
int metaIndex = newHeaderPart.IndexOf("<META", StringComparison.CurrentCultureIgnoreCase);
//meta tag found
if (metaIndex >= 0)
{
//remove the current title information
newHeaderPart.Replace(titleText, string.Empty);
//inject the title information at first meta tag index
newHeaderPart = newHeaderPart.Insert(metaIndex, titleText);
}
pageHtml = pageHtml.Replace(headerPart, newHeaderPart);
}
}
and in pages you can use the following version of the Render method
Code: Select all
protected override void Render(HtmlTextWriter writer)
{
string pageHtml = string.Empty;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
base.Render(hw);
pageHtml = sw.ToString();
PageHelper.AdjustHTML(ref pageHtml);
hw.Close();
}
sw.Close();
}
writer.Write(pageHtml);
}
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: <title> and <meta> tags - again
Thank you, mazhar. I will work on the title tag. On moving it all to Pagehelper.cs, I was just looking for a way to have the code in only one place, but I understand now why I can't.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: <title> and <meta> tags - again
Thank you for posting this code! I did some fine-tuning - the casing on "META" didn't match what I had, and the <title> in its original position was not getting removed. This is the modified code that works for me:
protected override void Render(HtmlTextWriter writer)
{
string pageHtml = string.Empty;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
base.Render(hw);
pageHtml = sw.ToString();
if (pageHtml.Contains("<head") && pageHtml.Contains("</head>"))
{
int headStartIndex = pageHtml.IndexOf("<head");
int headEndIndex = pageHtml.IndexOf("</head>");
string headerPart = pageHtml.Substring(headStartIndex, ((headEndIndex + 7) - headStartIndex));
StringBuilder sb = new StringBuilder(headerPart);
sb.Replace("<link", "\r<link");
sb.Replace("<Meta", "\r<Meta");
sb.Replace("<style", "\r<style");
int sindex = headerPart.IndexOf("<title>");
int eindex = headerPart.IndexOf("</title>");
string titleTag = headerPart.Substring(sindex, (eindex + 8 ) - sindex);
string titleText = headerPart.Substring((sindex + 7), (eindex - (sindex + 7)));
titleText = titleText.Replace("\r", string.Empty);
titleText = titleText.Replace("\t", string.Empty);
titleText = titleText.Replace("\n", string.Empty);
titleText.Trim();
titleText = String.Format("\r<title>{0}</title>", titleText);
sb.Replace(titleTag, titleText);
sb.Replace("</head>", "\r</head>");
string newHeaderPart = sb.ToString();
//find out the index of first meta tag
int metaIndex = newHeaderPart.IndexOf("<Meta", StringComparison.CurrentCultureIgnoreCase);
//meta tag found
if (metaIndex >= 0)
{
//remove the current title information
string updatedHeaderPart = newHeaderPart.Replace(titleText, string.Empty);
//inject the title information at first meta tag index
newHeaderPart = updatedHeaderPart.Insert(metaIndex-1, titleText);
}
pageHtml = pageHtml.Replace(headerPart, newHeaderPart);
}
hw.Close();
}
sw.Close();
}
writer.Write(pageHtml);
}
protected override void Render(HtmlTextWriter writer)
{
string pageHtml = string.Empty;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
base.Render(hw);
pageHtml = sw.ToString();
if (pageHtml.Contains("<head") && pageHtml.Contains("</head>"))
{
int headStartIndex = pageHtml.IndexOf("<head");
int headEndIndex = pageHtml.IndexOf("</head>");
string headerPart = pageHtml.Substring(headStartIndex, ((headEndIndex + 7) - headStartIndex));
StringBuilder sb = new StringBuilder(headerPart);
sb.Replace("<link", "\r<link");
sb.Replace("<Meta", "\r<Meta");
sb.Replace("<style", "\r<style");
int sindex = headerPart.IndexOf("<title>");
int eindex = headerPart.IndexOf("</title>");
string titleTag = headerPart.Substring(sindex, (eindex + 8 ) - sindex);
string titleText = headerPart.Substring((sindex + 7), (eindex - (sindex + 7)));
titleText = titleText.Replace("\r", string.Empty);
titleText = titleText.Replace("\t", string.Empty);
titleText = titleText.Replace("\n", string.Empty);
titleText.Trim();
titleText = String.Format("\r<title>{0}</title>", titleText);
sb.Replace(titleTag, titleText);
sb.Replace("</head>", "\r</head>");
string newHeaderPart = sb.ToString();
//find out the index of first meta tag
int metaIndex = newHeaderPart.IndexOf("<Meta", StringComparison.CurrentCultureIgnoreCase);
//meta tag found
if (metaIndex >= 0)
{
//remove the current title information
string updatedHeaderPart = newHeaderPart.Replace(titleText, string.Empty);
//inject the title information at first meta tag index
newHeaderPart = updatedHeaderPart.Insert(metaIndex-1, titleText);
}
pageHtml = pageHtml.Replace(headerPart, newHeaderPart);
}
hw.Close();
}
sw.Close();
}
writer.Write(pageHtml);
}
Re: <title> and <meta> tags - again
Thanks for sharing the code krissato 

Re: <title> and <meta> tags - again
Were exactly should this code be placed?
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot
Brewhaus (America) Inc.
Hot Sauce Depot
Re: <title> and <meta> tags - again
In all root pages of website for example Default.aspx, ContactUs.aspx etc.