How to get the compiled version of aspx page for r

2019-08-18 09:54发布

问题:

Given the path of an aspx page on my site that's been precompiled, how can get the path to compiled version (dll or other) from a second page on my site so that I can examine its properties, methods and classes via reflection?

Or some other way to generate method/property lists from aspx pages?

回答1:

What your looking for should be in the bin folder of your server. You can't access the bin folder through your browser due to security issues. So you will need to open your server's ISS folder with either a ftp client or from the server locally. Then you can use a reflector against it once you download it.



回答2:

I believe that they should both be in the same assembly. You can test this out.

Just drop the following snippet at the top of your aspx page:

<%=this.GetType().Assembly.Location %>

This will give you the directory of the dll. Alternatively, you could do this:

<%=typeof(MyWebsite.TargetPageType).Assembly.Location %>

substituting the type of the page you're wanting to examine.



回答3:

You could probably use this:

System.Web.Compilation.BuildManager.GetCompiledType(Me.Request.Url.AbsolutePath)


回答4:

ASP.Net compiles pages on demand, which basically means you need to use the BuildManager to ensure that they're there. Basically it checks if it's there and up to date - and if it's not it will create the assembly.

var pg = System.Web.Compilation.BuildManager.GetCompiledType([relative path]);

If you're already on the page, it's of course easy:

var pg = this;

Other information here

Everything using the Assembly.Location to dynamically load assemblies from that path is incorrect and can even break your application. If you do, you run the risk of loading an old assembly - and when the ASP.NET worker figures out it should re-compile the thing, loading the new assembly could fail due to name conflicts. You're also looking at old code. To cut it short: Don't Do That.