Rico Suter's blog.
 


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

[HttpGet("deployTime")]
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);
}


Discussion