Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3802534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:13:25+00:00 2026-05-19T14:13:25+00:00

I have read lots of article on how to auto-version your CSS/JS files –

  • 0

I have read lots of article on how to auto-version your CSS/JS files – but none of these really provide an elegant way to do this in ASP.NET MVC.

This link – How to force browser to reload cached CSS/JS files? – provides a solution for Apache – but I’m a little confused how this could be implemented via ASP.NET MVC ?

Would anyone be able to provide some advice how to do this on IIS7 and ASP.NET MVC – so that CSS/JS files automatically have a version number inserted in the URL without changing the location of the file ?

That is, so links come out link this etc presumably using the URL Rewrite or ?

<link rel="stylesheet" href="/css/structure.1194900443.css" type="text/css" />
<script type="text/javascript" src="/scripts/prototype.1197993206.js"></script>

Thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:13:26+00:00Added an answer on May 19, 2026 at 2:13 pm

    When faced with this problem I wrote a series of wrapper functions around the UrlHelper‘s Content method:

    EDIT:

    Following the discussions in the comments below I updated this code:

    public static class UrlHelperExtensions
    {
        private readonly static string _version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
    
        private static string GetAssetsRoot()
        {
            string root = ConfigurationManager.AppSettings["AssetsRoot"];
            return root.IsNullOrEmpty() ? "~" : root;
        }
    
        public static string Image(this UrlHelper helper, string fileName)
        {
            return helper.Content(string.Format("{0}/v{2}/assets/img/{1}", GetAssetsRoot(), fileName, _version));
        }
    
        public static string Asset(this UrlHelper helper, string fileName)
        {
            return helper.Content(string.Format("{0}/v{2}/assets/{1}", GetAssetsRoot(), fileName, _version));
        }
    
        public static string Stylesheet(this UrlHelper helper, string fileName)
        {
            return helper.Content(string.Format("{0}/v{2}/assets/css/{1}", GetAssetsRoot(), fileName, _version));
        }
    
        public static string Script(this UrlHelper helper, string fileName)
        {
            return helper.Content(string.Format("{0}/v{2}/assets/js/{1}", GetAssetsRoot(), fileName, _version));
        }
    }
    

    Using these functions in conjunction with the following rewrite rule should work:

    <rewrite>
      <rules>
        <rule name="Rewrite assets">
          <match url="^v(.*?)/assets/(.*?)" />
          <action type="Rewrite" url="/assets/{R:2}" />
        </rule>
      </rules>
    </rewrite>
    

    This article discusses how to create rewrite rules on IIS7.

    This code uses the version number of the current assembly as a query string parameter on the file path’s it emits. When I do an update to the site and the build number increments, so does the querystring parameter on the file, and so the user agent will re-download the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read lots of information about page caching and partial page caching in
From the .net 4.0 previews I have read until now there has been lots
I've read lots of articles that condemn the excessive use of divs. I have
If I have a string in a div <div id=article> lots of text goes
I have read through several reviews on Amazon and some books seem outdated. I
I have read a lot that LISP can redefine syntax on the fly, presumably
I have read about partial methods in the latest C# language specification , so
I have read that using database keys in a URL is a bad thing
I have read this post about how to test private methods. I usually do
I have read on Stack Overflow some people that have converting to C#2.0 to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.