views:

251

answers:

1

I'm using URL routing (with WebForms) in the following format:

http://host/project/{projectid}/{pageName}

Another option is that the user is refering to a subapplication:

http://host/project/{projectid}/{application}/{pageName}

The subapplication isn't a new web application, simply a virtual directory.
My subapplication does have a web.config, which contains some specific appsettings/connstrings.

Everything works fine without the URL routing.

However when I request an URL in the routed form the web.config of the subapplication isn't processed and I get a null reference on all of the appsettings/connstrings (through ConfigurationManager).

Here's the code in my custom handler:

string path = String.Format(_pagesFormat, application, pageName);   
return (IHttpHandler) BuildManager.CreateInstanceFromVirtualPath(path, typeof(Page));

It works if I would change my route to http://host/{application}/{projectid}/{pageName}
This probably triggers IIS to load the web.config of the virtual directory as well.

Can I somehow force the settings of the nested web.config to be loaded?

EDIT:
This person has a similar problem:
http://forums.asp.net/p/1452479/3317775.aspx

Any ideas?

+1  A: 

For some reason the system.web tag and a few other tags are being processed by the
web.config (that resides in the virtual directory).

I've decided to put my application settings and connection string settings into two separate files in the root:

  • web.config in the root (IS, compilation, handler configuration)
  • web.AppSettings.config in the root
  • web.Connections.config in the root

  • web.config per virtual directory (user control, masterpage configuration)

Zyphrax