Tuesday, September 19, 2006

HttpModule remove bug Part 2 - The workaround

Well, I’ve found a way for not loading the HttpModule, using the web.config <remove … >, but it isn’t pretty…

How?

You still have to put the HttpModule’s assembly inside the bin/ directory of the child web application and add the remove element for HttpModules in the web.config.

Then, the reference to the HttpModule will be removed.

Undocumented feature

The documentation MSDN doens’t say anything about explicitly putting the HttpModule’s assembly inside the bin/ directory, of the child web application, EVEN if you don’t want to use it.

If the the remove element for HttpModules was created like the remove element for HttpHandlers we wouldn’t have this problem, because the remove element for HttpHandlers has an attribute called path. There you can set the path to the HttpHandler that you want to remove…

Who said that life was fair anyway?

See you next time!

Posted by BCoelho2000 at 21:14:13 | Permalink | No Comments »

Sunday, September 17, 2006

HttpModule remove bug - ASP .NET 1.1

Hi everyone!

This time, I’m here to warn you of a bug in ASP .NET 1.1.

The scenario

Let’s say that you have a web application. Let’s called HttpModuleIssue. That web application has a child web application that I’ve called HttpModuleIssueSubApp.

Let’s look how this is configured in IIS.

Each one of this web applications has a Web.Config file.

Quick Web.Config talk

A web.config file is, has you know, a special file where you can manage the configuration of your application.

The root of the ASP.NET configuration hierarchy is a file referred to as the root Web.config file, and it is located in the same directory as the Machine.config file. The root Web.config file inherits all of the settings in the Machine.config file. The root Web.config file includes settings that apply to all of the ASP.NET applications that run a specific version of the .NET Framework. Because each ASP.NET application inherits default configuration settings from the root Web.config file, you need to create Web.config files only for settings that override the default settings. More info here.

Adding a HttpModule

Let’s add a HttpModule to our main web application HttpModuleIssue.

The HttpModule doesn’t do anything usefull… it’s only to show you the dreaded bug. Anyway, here it is:


using System;
using System.Web;

namespace HttpModuleExProject
{
    ///
    /// Summary description for HttpModuleEx.
    ///
    public class HttpModuleEx: IHttpModule
    {
        public void Init(HttpApplication app)
        {
            // Register for pipeline events
        }

        public void Dispose()
        {
            // Nothing to do here
        }
    }

}

 


Now, not only do we have to put the assembly of our HttpModule inside the bin directory of HttpModuleIssue, but we must also add an entry to the HttpModuleIssue’s web.config file registering the HttpModule.


<system.web>
    <httpModules>
        <add name="HttpModuleEx"
             type="HttpModuleExProject.HttpModuleEx, HttpModuleEx" />
    </httpModules>

The name attribute can be any name that we like. The type attribute must be in the format “namespace.typeName, typename”.

This works with no problems. But if you visite a page inside the web application HttpModuleIssueSubApp, you will see this runtime error:

Well, after our previous web.config talk, that should be expected. After all, HttpModuleIssueSubApp doens’t want to use that HttpModule, but it’s web.config file inherits the registration of the HttpModule.

The solution that should work

According to the documentation you can remove the HttpModule that some parent web application might have registered. It should be as simple as putting the following code inHttpModuleIssueSubApp’s web.config file:


<system.web>
     <httpModules>
        <remove name="HttpModuleEx" />
    </httpModules>

The sad true

Unfortunately, it doens’t work at all. The runtime error still happens. I’ve seen a couple of developers complaning about this issue… This issue was found using ASP.NET 1.1.

The sad solution

The only solution is copying the HttpModule assembly to the child web applications…

You can download the source code used for this article here.

Any comments about this bug/issue are appreciated.

See you next time!

Posted by BCoelho2000 at 08:44:18 | Permalink | Comments (1) »

Saturday, September 16, 2006

Thought of the day

Computers,  give us precious time to spend on a very important thing that they can’t do: think.

Think how to resolve a problem.

How to think like an engineer.

Free your mind!

Posted by BCoelho2000 at 23:41:22 | Permalink | No Comments »