ninety
ninety

Reputation: 19

IIS 7.5 ASP.OLD .NET4 class Library (dll) not reading .Config

I'm calling a .NET4 class library from an ASP.OLD (classic) page on IIS 7.5. All the interop is OK & the call is working. My problem is, the class library is not getting any settings from a .config file when it's called.

I have a we.config in the same folder from which the ASP.OLD file is served. I have an App.Config from the folder in which the class library is registered.

I've even tried an app.config file in the IIS folder & a web.config in the class library folder - still no joy.

The IIS app pool is running in classic pipeline mode. If I open the Application Settings in IIS manager for the web site the values are there.

Where should I put the .config file & what should it be called?

Ta! N

Upvotes: 1

Views: 534

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189437

The problem is that calling a .NET dll via COM interop from ASP will load the .NET dll into the default AppDomain. The .NET dll will have no awareness of ASP.NET, web.configs, current IIS request etc that a dll loaded into a ASP.NET app domain would. It is as if it has been loaded simply by some running exe which in fact is the case.

The configuration information that your dll will have access to will be the config file for the w3wp.exe. Hence one way to get this config information in your dll (although you understand I'm not actually recommending this approach) is to add a w3wp.exe.config file to the windows\system32\inetsrv folder. This of course is a horrible thing to do and you shouldn't do it.

What I would actually do is create a COM visible class whose job it is to expose some properties that represent the various configuration settings. The property setter would assign values into the dll's static space. Then add to the Application start event in the ASP app's Global.asa file some code to instance this object and assign the configuration values.

The dll would internally refer to the static values that are set by the above code.

Note that all ASP applications that run in the same app pool would need to have identical configuration since they will share the same app domain. This is better than the other approach where all ASP applications on the same machine would end sharing a common configuration.

Upvotes: 1

Related Questions