Remove HttpModule for a subfolder
我把WEB程序放在了虚拟根下,把WEBSERVICE放在了WEBSVICE虚拟目录下,在WEB项目中使用了HTTPMODULE后,发现WEB项目一切完好,然而WEBSERVICE不能使用,说是找不到HTTPMODULE类,先使用了REMOVE,CLEAR于WEBSERVICE的WEB.CONFIG中,发现错误依旧。
上网一搜,遇到同样问题的大有人在,可是好多文章无解,于是换了N个搜索条件。知道了问题发生的原因:
i already found the problem, in this third party httpModule i found the following Codeline:
Application.AuthenticateRequest += new EventHandler(Application_Authenticate)
That means that the ApplicationAuthenticate always getting invoked, 'cuz of this statement, even of that <remove> & <clear/> sections. Application is a global object for all files & subdirectories.
与我的推测大体相同,但如何解决呢,查到说有两种方法,一个是把HTTPMODULE类所在的DLL放到BIN下,另一个是把该DLL放到GAC中,第二种方法我不太喜欢。然而事实上是我已经把该DLL引入到WEBSERVICE项目中了。在WEBSERVICE项目中试一下,发现即便引入该DLL找不到该类(用INTELL...就可以试出来了),而有WEB项目中很正常。关掉解决方案,重新引用,问题依旧。
不到黄河不死心,终于,找到了如下的一段文字,大是高兴啊。
I have a web.config with the following httpModule definition:
<httpModules>
<add name="MyModule" type="MyAssembly.MyModuleHandler, MyAssembly" />
</httpModules>
When "MyAssembly" is in the web application bin directory run without problems. The problem raises when I have registered "MyAssembly" in the Gac. When the web application starts, fails indicating that MyAssembly can't be found. If I put the Strong Name, all runs again.
Because of deployment inconveniences, I want to know if there is another way to specify the type name for the module handler without using the strong name.
I have found 2 ways to resolve this issue:
1) Using the <bindingRedirect> element, where you can specify which version to use depending of the referenced versión (more info at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfBindingRedirect.asp)
If you put the bindingRedirect element at the machine.config, every application in the server will use the same version
2) Using the AssemblyFileVersionAttribute instead of AssemblyVersionAttribute to diferenciate the assembly generated in each build. I this case, you only need to reference the assembly with the strong name (the strong name doesn't change in each build), if the assembly is located in the GAC, the loader get it. If the assembly is in the local folder and not in the GAC, it's took from the local path.
第一种方法不喜欢,于是首先使用了AssemblyFileVersionAttribute ,提示我所用的DLL已经被另外一个进程使用,关掉SOLUTION再重新打开,哈哈,一切都正常了。当然,最后还得在WEBSERVICE的WEB.CONFIG中加上一句:
<httpModules>
<remove name="MyModule"/>
</httpModules>
当然,在找到的其他文章中,好象也有其他的解决办法(没有测试过结果),但我选的路,是我最喜欢的。
浙公网安备 33010602011771号