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

  • This paper introduces IBM Java on the IBM PowerLinux 7R2 server and describes IBM's implementation of the Java platform, which includes IBM's Java Virtual Machine and development toolkit.

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds