How to programmatically retrieve the deployment time of an ASP.NET web site

May 26, 2016, (updated on August 24, 2017), Software Development

In one of my web projects, I wanted to append the web site deployment time to the JavaScript URLs. This way the browser uses the cached file version until a new web site version is deployed.

To do so, I looked for a way to read the deployment time of the currently running ASP.NET web site. It’s actually very simple, just read the modified date of the applications Web.config:

var configPath = Server.MapPath("~/Web.config");
var deploymentTime = File.GetLastWriteTime(configPath);

Do you known a better way to do this?

Update: Retrieve deployment time in ASP.NET Core

public DateTime GetDeployTime([FromServices]IHostingEnvironment hostingEnvironment)
    var rootPath = hostingEnvironment.ContentRootPath;
    var file = System.IO.Path.Combine(rootPath, "appsettings.json");
    return System.IO.File.GetLastWriteTime(file);


Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

This site uses Akismet to reduce spam. Learn how your comment data is processed.