3

I am trying to ensure that stale images/js/css files in a cache will not be used after deploying a new version of an asp.net web application.

I'm currently looking in to the js aspect of this. First, ALL of my own scripts are registered through the System.Web.UI.ScriptManager with normal urls to js files. So, I've subclassed the ScriptManager and I tack a ?ver='x.x.x.x' on the end of the script url. I don't see any problem with that for my scripts with normal urls, however there are always a lot of ScriptResource.axd references and I am concerned about these scripts.

So, for example, lets say in my next version I update the AjaxControlToolkit dll. Will the scriptResource.axd urls be different from the urls used by the previous AjaxControlToolkit? The scriptResources.axd look pretty funky to me, so I am hoping they are generated with a hash of the assembly or something? I've been through a ton of literature on scriptResource.axd, but I haven't found anything on this topic. Anyone have any ideas?

Thanks for reading.

1 Answer 1

11

You're partially right. The format of resource URL is WebResource.axd?d=encrypted identifier&t=time stamp value. The "d" stands for the requested Web Resource. The "t" is the timestamp for the requested assembly, which can help in determining if there have been any changes to the resource.

In brief, the first parameter is encrypted assemblyName + "|" + resourceName value (by using internal Page.EncryptString method); the secondparameter is number of ticks of assembly was last written to date (by using File.GetLastWriteTime method).

So, using the next version or your assembly will change the resource URL (rebuild the assembly and/or change its version).

More information could be found here:

Sign up to request clarification or add additional context in comments.

3 Comments

If this is true, why is the d part different between servers that are running the same version of my software? Or is that something that changed in ASP.NET 4.0?
@StarQuake, yes it seems Microsoft has changed the web resource generation mechanism. Now it is much more complicated
@StarQuake the MachineKey is used to encrypt the "asseblyName|resourceName" string. Make sure you are manually specifying the MachineKey to the be the same on both/all machines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.