0

I want to make a "properties style web form" that shows the application version for various .NET applications.

If I know the URL e.g. /someapp/default.aspx is it possible via reflection to execute that page and figure out the assembly version?

It's quite easy to find the executing assembly version, but without modifying the other application, is it possible?

Both the property page and the other application is running on the same server and in the same application pool.

Update: I've had some luck with

var url = "~/SomeApp/default.aspx";
var appType = System.Web.Compilation.BuildManager.GetCompiledType(url);

But navigating appType to find the assembly file version is not the same everytime.

starblue
  • 55,348
  • 14
  • 97
  • 151
Paaland
  • 682
  • 1
  • 10
  • 25

3 Answers3

1

Without modifying the web application to expose the version number through some URL-based retrieval (a simple page GET being the easy, obvious one), you're going to need to find a way to figure out where the DLL for the web application is from the URL.

If you can know the DLL's location, either by some convention (e.g. /appX/ is always at D:\Sites\appX\bin\appX.dll) or some configuration (you manually enter where each URL base's DLL is in a database), then you can retrieve that DLL's assembly version using the following code:

Assembly assembly = Assembly.LoadFrom("MyAssembly.dll");
Version ver = assembly.GetName().Version;

Code taken from this question.

Edit: I've had a little look around, and there are some APIs to inspect the IIS configuration, so this is certainly a route to explore if you're trying to get from the URL to the assembly location. This question has an example of getting the physical path from the application/site name, for example. Microsoft.Web.Administration is the assembly to explore.

Community
  • 1
  • 1
Paul Calcraft
  • 923
  • 6
  • 11
0

The ASP.NET engine streams nothing but HTML, javascript, etc.. to the client. There is nothing left of the assembly that gets passed in the response that can show what version of .net/asp.net that the application is running unless the developer on the server side adds it.

That said, you can gather some information from a utility at http://uptime.netcraft.com/up/graph that will give you some server information. Not down to the assembly version, but this is as close as I believe you are going to get.

Cos Callis
  • 5,051
  • 3
  • 30
  • 57
0

You may implement custom HttpModule, put it to the bin folder of each application that you wish to monitor and append register this module in web.config files. In this module for example you should handle request, retrieve all required information and put it to response cookie.

Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68