Skip to content
Versioned content URLs in ASP.NET MVC 5
C# PowerShell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
AspNet.MVC5.AssetVersioning.Tests
src
tools
.gitignore
README.md

README.md

AspNet.Mvc.AssetVersioning

Adds a UrlHelper.VersionedContent URL extension helper to append SHA256 hash to content URLs in ASP.NET MVC 5.

Install

Install-Package AspNet.Mvc.AssetVersioning

Usage

In Views/web.config, add:

<configuration>
  ...
  <system.web.webPages.razor>
    <pages ...>
      <namespaces>
        ...
        <add namespace="System.Web.Mvc.AssetVersioning"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

You can then use the helper in .cshtml files like so:

<script type="text/javascript" src="@Url.VersionedContent("~/scripts/jquery.js")"></script>

And the helper will append a query string parameter containing the SHA256 hash of the content. This is cached for the lifetime of the request cache (HttpContext.Cache).

You can’t perform that action at this time.