2014-10-29 47 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