ASP.NET Tip: Create a Perpetual Page Footer

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.



Comments

  • Simple jet effective

    Posted by rpredan on 09/07/2006 03:54am

    Thank you very much. Though obvious and simple solution, I was making the mistake exactly described in the article for 5 years - until today :).

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds