1

我希望将 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)

使用堆栈跟踪:

[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.
4

1 回答 1

1

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

  1. 通过执行将带有模块的程序集添加到 GACgacutil.exe -i path_to_project\bin\MyHandlerAssembly.dll
  2. 重新启动 IIS
  3. 添加类型的处理程序映射MyHandlerAssembly.MyHandler, MyHandlerAssembly, Version=X.X.X.X, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXX(您的程序集中的新类型将在 IIS 重新启动后可用)
于 2013-06-07T13:10:39.077 回答