我需要将自定义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>
但是,当我们执行该网站上的页面处理程序似乎并没有工作,因为我们没有得到重定向到谷歌。这里有什么问题?