【问题标题】:How to add HttpHandler located in GAC to IIS7.5如何将位于GAC中的HttpHandler添加到IIS7.5
【发布时间】:2013-06-06 13:52:43
【问题描述】:

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

当我在全局级别添加 Managed Handler 时,我使它适用于特定应用程序

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

和 .dll 到特定应用程序的 /bin 目录。在这一点上,除了我不打算将此 .dll 添加到每个应用程序之外,所有工作都按预期工作。

于是我将MyHandlerAssembly添加到GAC,然后根据gacutil -l MyHandler修改type

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

【问题讨论】:

    标签: iis httphandler .net-assembly gac


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多