2014-10-29 45 views
1

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

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

的HTTP模块已经减少到最简单的可能电平 - 当模块被创建,设置的,请求开始和请求结束,如下记录:

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"); 
     } 
    } 
} 

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

在此先感谢

+0

请确保您的HttpModule已添加到IIS。 转到IIS - >您的网站 - >模块 - >添加托管模块 ,并再次点击网站的请求 – IMR 2015-04-16 23:43:23

回答

1

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

要使用PowerShell使用添加这些模块:

Install-WindowsFeature Web-Net-Ext 
Install-WindowsFeature Web-Net-Ext45