"Could not load type xxx" 在 IIS 8.5 中用于 IHttpModule

"Could not load type xxx" in IIS 8.5 for IHttpModule

我在 ASP.NET

中创建了一个 http 模块
namespace aellerb.App_Code
{
  public class ContentParser : IHttpModule
  {
     ...
  }
}

在 web.config 中配置如下:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="ContentParser" type="aellerb.App_Code.ContentParser"/>
  </modules>
</system.webServer>

当 运行 在 IISExpress 中本地时,该模块工作并加载。但是,当我在 IIS 8.5 下将它部署到我的 Web 主机时,我得到:

System.Web.HttpException:无法加载类型 'aellerb.App_Code.ContentParser'。

知道我在这里遗漏了什么吗?

浏览此 article 我发现 "Custom handler and module source code can be put in the App_Code folder of an application..."。

所以我在服务器上创建了一个名为 App_Code 的文件夹,并将我的 http 模块 .cs 文件复制到那里。它现在加载并且问题已解决。

您可能需要声明程序集名称 试试这个

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="ContentParser" type="aellerb.App_Code.ContentParser, {your_web_application_dllname_without_extention_name}"/>
  </modules>
</system.webServer>