Dealing with hashed filenames in ASP.Net MVC
21 Feb 2018
This is an extended part of article DEALING WITH HASHED FILENAMES in .net core. Kindly go through the linked article to know more on the background detail for this requirement.
This article primarily focuses on how to deal with the hashed filenames in production builds and non-hashed ones on development machine.
- Create a key in your web.config to identify if you want the bundles with minification and hased version numbers.
<appSettings> <!-- This should be transformed to true in production i.e., web.release.config -> <add key="enableHash" value="false" /> </appSettings>
- Validate the appSettings in the Controller action and set it to view model.
model.enableHash = Configuration.AppSettings["enableHash"] .equals("true", StringComparision.CurrentCultureIgnorecase);
- In the Bundle configuration, include the script files to render as follows
- In your layout.cshtml, you can check the application setting value (
enableHash) and link the appropriate file.
Above change allows the Hot Module replace to happen normally when appSetting