October 22, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

ASP.NET Tip: Create a Perpetual Page Footer

  • July 19, 2006
  • By Eric Smith
  • Send Email »
  • More Articles »

One of the easiest ways to tell if a Web site has been updated recently is to check the bottoms of its pages. Many sites include page footers with their copyright dates. Unfortunately, webmasters often forget to change the date each year, making their sites look outdated to users.

Page footers also often include contact information to reach the webmaster, as well as a date/time stamp to determine when the page was last modified. The footer format I use for my Web site looks something like this:

Copyright © 2001-2006 by Northstar Computer Systems.
Comments, questions, or problems? Contact the webmaster!

The starting date of 2001 is when the Web site was first published, and the second date is the current year. The webmaster link is an e-mail link (mailto) to the webmaster@domain.ext mailbox address. Here's the HTML part of the page to do this:

Copyright &copy; 2001-<asp:Label ID="lblYear"
runat="server" /> by Northstar Computer Systems.<br />
Comments, questions, or problems? Contact the
<asp:Label ID="lblEmail" runat="server" /><br />

The code-behind to make this work is fairly simple and can go into the OnLoad event of the page:

protected void Page_Load(object sender, EventArgs e)
{
   lblYear.Text = DateTime.Now.Year.ToString();
   lblEmail.Text = "<a href='mailto:webmaster@"
      + Request.Url.Host.Replace("www.", "") + "'>webmaster</a>";
}

Because the Host argument of Request.Url could bring back something like www.domain.ext, I replace the www with an empty string to give a proper e-mail address.

If you want to add the date and time when the particular file was modified, you can add this line to the HTML part of the page:

Last modified on <asp:Label ID="lblLastMod" runat="server" /><br />

And add this to the code-behind part of the page:

lblLastMod.Text =
System.IO.File.GetLastWriteTime(Server.MapPath(Request.
   Url.LocalPath)).ToLongDateString();

The end result is the following:

Copyright © 2001-2006 by Northstar Computer Systems.
Comments, questions, or problems? Contact the webmaster!
Last Modified: Thursday, June 1, 2006

If you are building a database-driven page, I recommend leaving off the Last Modified attribute because the content of the page will change more frequently than the actual ASPX page.

About the Author

Eric Smith is the owner of Northstar Computer Systems, a Web-hosting company based in Indianapolis, Indiana. He is also a MCT and MCSD who has been developing with .NET since 2001. In addition, he has written or contributed to 12 books covering .NET, ASP, and Visual Basic.






Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel