1

I'm working on a C# updatable ASP.NET 2.0 precompiled website. Since the code-behind cannot be altered (source code is not available), I'm adding code directly inside the aspx files (inside the script tag).

The trouble is that a lot of identical code must be copy-pasted between multiple aspx files. I created an external library in order to avoid code duplication then referenced this library from the website. However, I'm not able to access the library's classes from the aspx files. I tried adding an import directive at the top of the page but it is not working at all.

What would be the recommend way to avoid code duplication?

jdecuyper
  • 3,934
  • 9
  • 39
  • 51

1 Answers1

2

You could copy the assembly containing the common functionality to the bin folder and reference it to the <assemblies> section of the web.config. Now you can use it in aspx pages. But honestly that seems kind of perverted way to modify an ASP.NET site. Normally you would simply checkout the source code from version control, apply the necessary modifications, check-in, build, ship to staging, validate, ship to production. It's the way things should be done. Every other shipping into production process is simply ... (put whatever insult you would like here).

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Is this the correct way to add the reference inside the assemblies tag: ? I tried it this way but was not able to call any class from the aspx page. I wish I had access to the source code but it is unfortunately not an option. Thank you very much for your time! – jdecuyper Oct 18 '11 at 18:40
  • 1
    @jdecuyper, IIRC, you have to use the fully qualified assembly name: ``. – Darin Dimitrov Oct 18 '11 at 18:41
  • It worked without the PublicKey, I guess it is only necessary when you are using a signed assembly, right? Thanks a lot! – jdecuyper Oct 18 '11 at 19:17