When exploring the ASP.net tag in relation to Maxim Kornilov's answer (), I found a unique way to implement his concept of webapp-build-specific URLs on ASP.net MVC:
1) I incorporated the following code snippet into the main class of the web application (previously named MvcApplication) in Global.asax.cs:
#region Versioning
public static string Version => typeof(MvcApplication).Assembly.GetName().Version.ToString(); //note: syntax requires C# version >=6
public static DateTime LastUpdated => File.GetLastWriteTime(typeof(MvcApplication).Assembly.Location);
#endregion
The use of the someProperty => someReadOnlyExpression syntax is a concise way of defining properties introduced in C# 6.
2) In the Content/_Layout.cshtml file, instead of displaying the build number and datetime based on the main assembly as before, I opted for a simpler approach:
Version @somewebappname.MvcApplication.Version (@string.Format("{0:yyyy/MM/dd-HH:mm:ss}", somewebappname.MvcApplication.LastUpdated))
3) To ensure version-specific CSS loading, I modified the hardcoded CSS link in _Layout.cshtml to include the version parameter:
<link href='@Url.Content("~/Content/Site.css?version=" + somewebappname.MvcApplication.Version)' rel="stylesheet" type="text/css" />
This adjustment guarantees that the CSS URL is tied to a specific version, thus preventing unnecessary reloads with each page visit.
In order to automate the incrementing of the build number, I made changes in Properties/AssemblyInfo.cs following guidelines outlined in How to have an auto incrementing version number (Visual Studio)?:
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyFileVersion("1.0.*")] //don't use both AssemblyVersion and AssemblyFileVersion with auto-increment