We would like to embed some code in each ASP.NET page that queries its "Last Modified Date" and displays it at the bottom of the page.
In the past, we've relied on the person making any changes to the page to manually update the "This page last modified on (todays date)" text at the bottom of the page. Many times they forget to update this, which is causing some confusion as to when the information was last updated on that particular page. Since the site is not based on a CMS which could store this information in its back-end database, we're trying to do the determination as to when the page was last saved from the file system on the server and include that date in the text of the page.
I'm not sure how a page's being based on a Master Page plays into the "last modified date". What we're really looking for is for the content page file's LMD get queried so we can embed that in the text of the page and not the LMD of the Master Page it's based on.
Thanks!
Figured I'd post the answer to my question so that others can benefit.
My solution was to add a label control to your Master Page where you want the "Modified: + date saved" information displayed. We put ours in the footer:
Modified: <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
Then create a "Page_Load" event to the Master Page code behind (this website uses code behind and VB) and add the following code:
Dim strPath As String = Request.PhysicalPath
Label1.Text = "Modified: " + System.IO.File.GetLastWriteTime(strPath).ToString()
When the page loads, it will execute the code above and replace the "Label" text with the date the file was last saved to disk.
Hope this helps.
(If you know a better way, feel free to educate us in a comment)