BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

How To Avoid Load Of Http Handler From Root In Virtual Dir

If you create a virtual directory, your nested ASP.NET application will not see any assembly in /bin folder or root application. That is expected behavior since /bin folder should contain only assemblies that are specific for single application. If you want to use same assembly in many applications on server, you can register it to GAC (Global Assembly Cache).

Unlike /bin folders, web.config files inherits even if nested code is separate application in virtual directory. So, if your root ASP.NET application uses some http handler you have a potential problem. Handler's assembly will be invisible for application in virtual directory, but there is still a reference to http handler in <httpHandlers > section in root web.config file. So, nested ASP.NET application will not find assembly and will return an error:

Parser Error Message: Could not load file or assembly 'AssemblyName' or one of its dependencies. The system cannot find the file specified.

The solution depends of requirements, do you need that http handler in nested application or not? If you need it, you can copy assembly to /bin folder of nested application and it will work, or you can register an assembly to GAC to avoid multiple copying. If you don't need that http handler use <remove > tag in <httpHandlers > section.

For example, I use MSCaptcha http handler in root web application. The http handler is referenced in root web.config file with code like this:

<httpHandlers>
<add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"/>
...
</httpHandlers>

Then, I decided to try trial version of SmarterTrack, popular web application for customer support. I created virtual directory for this application, upload needed files and navigated web browser to see how it looks. But, web application just returned an error:

Parser Error Message: Could not load file or assembly 'MSCaptcha' or one of its dependencies. The system cannot find the file specified.

To remove a reference that caused an error, I used <remove > in the web.config of nested web application, with XML code like this:

<httpHandlers>
<remove verb="GET" path="CaptchaImage.axd" />
...

</httpHandlers>

That is all! Nested web application doesn't look for unnecessary assemblies any more. Happy coding!



Related articles:

1. How To Read Key/Value Pairs From AppSettings?
2. How To Modify Web.Config At Run Time

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.