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

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds