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

  • SEARCH
  • Home
  • 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 7443795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:23:22+00:00 2026-05-29T11:23:22+00:00

So I’m building a web app using C#.NET, and would like to add a

  • 0

So I’m building a web app using C#.NET, and would like to add a version number to file references. For example:

<script src="mysite/scripts/default.123.js"></script>

Each time I modify files in the web app, including cshtml, CSS, JS, or images, is it possible to have that version number incremented dynamically? In other words, how do I get [or create] the version number in the first place? Is it possible?

This is to avoid caching old copies on the client browsers, especially when being served via XHR. For reasons I don’t want to take the time to explain, I am NOT asking for alternative methods, such as dummmy parameters, no-cache meta tags, datetimestamps, CDN’s etc.

I’d like this number to correspond to the most recent version of file that was modified – maybe “build version” isn’t the right word. As Kyle Trauberman, assemblyversion might might work. However will this accomodate for changes to static resources, such as HTML or CSS? What is a good method for that?

  • 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-29T11:23:23+00:00Added an answer on May 29, 2026 at 11:23 am

    To solve this problem, I go with a slightly different approach. Rather than using a “version number”, I simply append the last modified date. To make things convenient, I wrote a helper method:

    public static HtmlString Script<T>(this HtmlHelper<T> html, string path)
    {
        var file = html.ViewContext.HttpContext.Server.MapPath(path);
        DateTime lastModified = File.GetLastWriteTime(file);
    
        TagBuilder builder = new TagBuilder("script");
        builder.Attributes["src"] = path + "?modified=" + lastModified.ToString("yyyyMMddhhmmss");
        return new HtmlString(builder.ToString());
    }
    

    Then in your views (not sure if you’re using MVC, but the solution is similar in either case), you can use:

    @Html.Script("/Scripts/common.js")
    

    Which will output:

    <script src="/Scripts/common.js?modified=20120129025804"></script>
    

    Note: Page Speed is not happy with the use of the query string. However, I tried changing it to using a “/” and that resulted in MVC taking over the routing for the file, and preventing IIS from handling it. Not sure how to resolve that.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.