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

  • It's time high-level executives and IT compliance officers recognize and acknowledge the danger of malicious insiders, an increased attack surface and the potential for breaches caused by employee error or negligence. See why there is extra emphasis on insider threats.

  • Today's competitive marketplace requires the organization to frequently release and deploy applications at the pace of user demands, with reduced cost, risk, and increased quality. This book defines the basics of application release and deployment, and provides best practices for implementation with resources for a deeper dive. Inside you will find: The business and technical drivers behind automated application release and deployment. Evaluation guides for application release and deployment solutions. …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds