Hi everyone, I'm working on an EXE-based host for Web Forms, broadly following the model that Scott Guthrie laid out in this post:
http://discuss.develop.com/archives/wa.exe?A2=ind0008C&L=DOTNET&P=R7109&I=-3 I've run into some behaviour that has me completely baffled, and wondered if anyone here could offer an explanation for it. Recently I had reason to add a custom module (adhering to System.Web.IHttpModule) to the Web.config file of some of the Web Forms we're using to test the host - the module provides a trivial form of authentication which ultimately prevents access via IIS while allowing access via our host process. <httpModules> <add name="MyAuthenticationModule" type="Myhost.MyAuthenticationModule,MyAssembly,Version=...,Culture=neutral,P ublicKeyToken=..."/> </httpModules> On the next execution of the Web Form in our host, an exception was thrown and ASP.NET returned the following marked-up message: ---------------------------------------------------------------------- Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: The module 'MyAuthenticationModule' is already in the application and cannot be added again ---------------------------------------------------------------------- and cited the Web.config file. The machine.config file makes no mention of my module. However if I remove this block from the Web.config and add the following to machine.config, <httpModules> <add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/> <add name="Session" type="System.Web.SessionState.SessionStateModule"/> <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/> <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/> <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule"/> <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/> <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/> <!-- here --> <add name="MyAuthenticationModule" type="Myhost.MyAuthenticationModule,MyAssembly,Version=...,Culture=neutral,P ublicKeyToken=..."/> </httpModules> the Web Form executes successfully under the host. I had a hunt through the Microsoft .NET framework managed DLLs, and I believe the message in the exception above is associated with the resource string key "Module_already_in_app", and only referenced or used in System.Web.dll (but I hope I'm wrong on this!) After disassembling the byte-code, the IL reveals that the exception is thrown at one point, in System.Web.Configuration.HttpModulesConfigurationHandler.Create(...) My next tactic was to instrument the IL with some Trace output, in particular right before the exception is thrown. Then I recompiled the IL and - signed it with a new private key - put it in the GAC - changed all references in Web.config and machine.config to point to the new assembly - rebuilt the module to refer to the new assembly - rebuilt the web form to refer to the new assembly This had limited success. It showed that Create(...) was called 7 times in close proximity, presumably for the machine.config modules, then once for my Web.config module. However, the exception was definitely not thrown. Processing proceeds until I received another exception - could not load aspnet_isapi.dll - which I haven't tried to work round (Process Explorer showed only one copy of System.Web was in loaded in our address space, but I assumed this was another symptom of the fact that System.Web wasn't the MS original). I suppose Create(..) may later be called again... Sorry for the extremely long message, but does anyone have a theory for why or how the "Module_already_in_app" exception is thrown? Has anyone successfully added an HttpModule to a Web.config file and processed the Web Form with a non aspnet_wp.exe-host? Or can anyone suggest how I might more successfully track this down? Any help is most sincerely appreciated. Thanks in advance, Graham You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.
