我需要將自定義httpHandler添加到現有IIS網站。我有一個Windows Server 2012 R2與IIS和IIS中我有一個WebSite運行一個ASP.NET解決方案,我無法訪問源。 ApplicationPool被配置爲以.Net 4.0和集成模式運行。如何創建自定義httpHandler並將其添加到現有IIS網站
我們想開發一個自定義的httpHandler作爲.dll,並在Handler Mappings下的WebSite中註冊它。要做到這一點,我們在Visual Studio 2015年一個新的動態鏈接Libary項目,下面的代碼創建:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
namespace MinimalStandaloneHttpHandler
{
public class Class1 : IHttpHandler
{
public Class1()
{
}
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
// This handler is called whenever a file ending
// in .sample is requested. A file with that extension
// does not need to exist.
context.Server.Transfer("http://www.google.com", false);
}
public bool IsReusable
{
// To enable pooling, return true here.
// This keeps the handler in memory.
get { return false; }
}
}
}
我們整理它和去IIS - >網站 - >處理程序映射 - >添加通配符腳本映射。
在這裏,我們添加了「*」作爲請求路徑,.dll的完整路徑和友好名稱。在處理程序映射下 - >我的處理程序 - >右鍵單擊 - >請求限制 - >映射 - >未選中「僅在請求映射到時調用處理程序:」。
處理程序現在列在啓用的處理程序下。現在web.config中得到了修正:
<configuration>
<system.webServer>
<handlers>
<add name="asdasd" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\inetpub\wwwroot\WebSiteStaticTest\MinimalStandaloneHttpHandler.dll" resourceType="File" requireAccess="None" preCondition="bitness32" />
</handlers>
</system.webServer>
</configuration>
但是,當我們執行該網站上的頁面處理程序似乎並沒有工作,因爲我們沒有得到重定向到谷歌。這裏有什麼問題?