You want to optimize your site for search engines by "loading" the title tag with the important keywords at the start. Additionally, you want to change titles easily and automatically in ASP.NET with content pages and one master page. Here we see how you can improve SEO using master pages in the C# programming language.
Page type: Home page Title: The New York Times - Breaking News, World News & Multimedia Page type: Landing page Article page Title: Justices Overturn Louisiana Death Sentence - New York Times
Here we see how to change titles in content pages with the SiteMap. First, in your master page markup file, such as "Site.Master", put a title tag with an ID on it. The tag has a runat=server attribute. This means that the tag will be processed on the server side.
<title id=Title1 runat="server" ></title>
Next, the example master page code-behind I show demonstrates using a Sitemap.web to detect whether we are on the root page. Look closely at how I use the ID attribute of the above title tag to change its Text contents.
protected void Page_Load(object sender, EventArgs e)
{
if (SiteMap.CurrentNode != SiteMap.RootNode)
{
Title1.Text = Page.Title + " - New York Times";
}
else
{
Title1.Text = "The New York Times - " + Page.Title;
}
}It switches title text positions. This code will programmatically move the title text content positions so that the root page has the company name first, and the other pages have it second.
It sets the title in content pages. Remember to make sure that the content pages have their title attribute set. Do not include the site name in the content pages' title attributes.
There are other ways to do this, but this automated approach is ideal in my opinion. As a software developer, you know that automating something instead of doing it manually can often lead to huge productivity gains and headache reductions.
Here we saw how you can change the title tags with ASP.NET using a Web.Sitemap and a .master along with its C# code-behind file. Use C# code on your master page to make your site much better, more usable, more attractive, and more highly ranked in Google and Yahoo.