如何将位于GAC中的HttpHandler添加到IIS7.5

时间:2013-06-06 13:52:43

标签: iis httphandler .net-assembly gac

我希望GAC中安装的 MyHandler 能够应用于IIS上托管的所有应用程序。

当我在全局级别添加托管处理程序时,我将其用于特定应用程序

<add name="MyHandler" path="*.txt" verb="*" type="MyHandlerAssembly.MyHandler" resourceType="Unspecified" preCondition="integratedMode" />

和.dll到特定应用程序的/ bin目录。此时所有工作都按预期工作,不包括我不是要将此.dll添加到每个应用程序。

所以我将 MyHandlerAssembly 添加到GAC,然后根据 gacutil -l MyHandler 修改了类型

<add name="MyHandler" path="*.txt" verb="*" type="MyHandlerAssembly.MyHandler, MyHandlerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8a3126c79b7aa959" resourceType="Unspecified" preCondition="integratedMode" />

我收到错误:

System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

使用stacktrace:

[FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)]
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +314
   System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +95
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +124
   System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type) +47
   System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +18
   System.Web.Configuration.HandlerFactoryCache..ctor(String type) +27
   System.Web.HttpApplication.GetFactory(String type) +95
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +352
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

我做错了什么?感谢。

更新1。

还尝试将我的程序集添加到C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config但收到错误:

Could not load file or assembly 'MyHandlerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8a3126c79b7aa959' or one of its dependencies. The system cannot find the file specified.

1 个答案:

答案 0 :(得分:1)

将程序集添加到GAC以应用更改后需要重新启动IIS 。完整的解决方案是:

  1. 通过执行gacutil.exe -i path_to_project\bin\MyHandlerAssembly.dll
  2. 将包含模块的程序集添加到GAC
  3. 重新启动IIS
  4. 添加类型为MyHandlerAssembly.MyHandler, MyHandlerAssembly, Version=X.X.X.X, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXX的处理程序映射(IIS重新启动后,程序集中的新类型将可用)