2

I want to implement some cache busting code in my library which can be integrated with ASP.NET web applications/sites. This will be implemented through appending a version string to the end of URLs. The default version provider I'd like to provide for cache busting would use the assembly version of the host web site.

Currently, this is essentially how I'm extracting this version number:

HttpContext.Current
           .ApplicationInstance
           .GetType()
           .Assembly
           .GetName()
           .Version
           .ToString()

Unfortunately, at least for my sample test site, Assembly for the application instance is a generated assembly (I guess because the global.asax is compiled into a new assembly). In Get web application assembly name, regardless of current executing assembly, SLaks says you can use BaseType to get the actual site assembly's type, but I assume that if a site doesn't use a global.asax file, BaseType would give you something in the BCL.

Is there any reliable way to extract the assembly version number for an ASP.NET web application? I'm also up for alternative approaches for generating a unique-per-build token that wouldn't require extra build steps for the application developer.

1
  • try using this.GetType() ..... instead Commented May 21, 2014 at 21:34

1 Answer 1

2

My strategy is to pick a type from among my custom types and ask the runtime about the version number of this type's assembly.

 typeof( SomeKnownType ).Assembly.GetName().Version
Sign up to request clarification or add additional context in comments.

2 Comments

That would work if the site this library was integrated with was under my code base. However, my question is about my library which others plug into their web sites. I don't have a way of knowing about the types that are in their web site assembly.
Then let the feed your configuration with a delegate or a class implementing some interface that you will call and thus get the version info. This isn't automatic but gives the full control over the required parameter.

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.