Dragomok
Dragomok

Reputation: 622

Get the actual last modified date for the requested page in WebForms

I want to put the last modified date of (the .aspx file responsible for) the currently viewed page into a footer of a Web Forms site.

I am working on a default Web Forms template from Visual Studio 2015 and building the project for .NET 4.5. In Site.Master, I have modified the footer like so:

<footer>
    <p>
        Page last updated on:
        <asp:Label ID="modyfikacja" runat="server" Text="coś nie poszło" />
    </p>
</footer>

and modified Page_Load() method in Site.Master.cs like so:

protected void Page_Load(object sender, EventArgs e)
{
    string _site = Server.MapPath(HttpContext.Current.Request.Url.AbsolutePath);
    modyfikacja.Text = "(" + _site + ") " + File.GetLastWriteTime(_site).ToString();
}

Unfortunately, that doesn't actually work all the way through:

There are loads of alternative solutions to getting the file, proposed all over web (and on StackOverflow), but none of them work, either. If I change the _site variable to...

So - how exactly can I get that .aspx file?

PS. There is a somewhat similar question, but it seems short, vague and poorly worded - SO's Similar Questions and myself think it's about getting the .aspx file, while its two answers think it's about getting the URL.

Upvotes: 1

Views: 989

Answers (1)

Moin
Moin

Reputation: 1

try this below code:

string ASPXphysicalpath = Page.Request.PhysicalPath;
lblLastModified.Text = System.IO.File.GetLastWriteTime(ASPXphysicalpath).ToString();

Upvotes: 0

Related Questions