【问题标题】:HttpModule in IIS 8.5 not being loadedIIS 8.5 中的 HttpModule 未加载
【发布时间】:2014-12-25 15:23:58
【问题描述】:

我用 C# 为 IIS 8.5 编写了一个简单的托管 HttpModule,并将其安装到全局程序集缓存中(CLR 版本 4.0.30319)。这被 IIS 检测为存在,我已将其作为模块安装在应用程序主机级别。

不幸的是,它似乎根本没有被执行。我们只提供静态内容,但由于 IIS 在集成模式下运行,我的印象是 HttpModules 是针对所有请求执行的,而不仅仅是 ASP.NET 管道中的请求。

HttpModule 已被简化为最简单的级别 - 记录模块创建、处置、请求开始和请求结束时的日志,如下所示:

using System;
using System.Web;
using System.Collections.Specialized;
using System.IO;

public class ServerLoggingModule : IHttpModule
{
    public ServerLoggingModule()
    {
       using (StreamWriter file = new StreamWriter(@"C:\LocalIISAuth\logs\iis.log"))
       {
           file.WriteLine("Created module");
       }
    }

    public string ModuleName
    {
        get { return "ServerMaskModule"; }
    }

    public void Dispose()
    {
        using (StreamWriter file = new StreamWriter(@"C:\LocalIISAuth\logs\iis.log"))
        {
            file.WriteLine("Disposed of module");
        }    
    }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(ServerLoggingModule.BeginRequestHandler);
        context.EndRequest += new EventHandler(ServerLoggingModule.EndRequestHandler);
    }

    protected static void BeginRequestHandler(Object sender, EventArgs e)
    {
        using (StreamWriter file = new StreamWriter(@"C:\LocalIISAuth\logs\iis.log"))
        {
            file.WriteLine("BeginRequest");
        }
    }

    protected static void EndRequestHandler(Object sender, EventArgs e)
    {
        using (StreamWriter file = new StreamWriter(@"C:\LocalIISAuth\logs\iis.log"))
        {
            file.WriteLine("EndRequest");
        }
    }
}

请求到达模块所在的管道中的点,但似乎只是跳过了模块。没有显示错误,页面显示正常。

提前致谢

【问题讨论】:

  • 请确保您的 HttpModule 已添加到 IIS。转到 IIS -> 您的网站 -> 模块-> 添加托管模块并再次点击该网站并发出请求

标签: c# .net iis httpmodule iis-8.5


【解决方案1】:

事实证明,我们没有启用 .NET 可扩展性 Windows 功能,导致模块无法加载。不幸的是,IIS 确实允许您将托管模块添加到其中,尽管它肯定知道它永远无法启动它!

使用 PowerShell 添加这些模块:

Install-WindowsFeature Web-Net-Ext
Install-WindowsFeature Web-Net-Ext45 
【解决方案2】:

有时池会以某种方式损坏,重新创建池可以解决此类问题。希望它可以帮助某人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多