I need to add a custom httpHandler to an existing IIS WebSite. I have a Windows Server 2012 R2 with IIS and in IIS i have a WebSite which runs an ASP.NET solution where i have no access to the sources. The ApplicationPool is configured to run with .Net 4.0 and in Integrated Mode.
We want to develop a custom httpHandler as .dll and register this within the WebSite under Handler Mappings. To do so we have created in Visual Studio 2015 a new Dynamic Linked Libary project with the following code:
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; }
}
}
}
We have compiled it and the went to IIS -> WebSite -> Handler Mappings -> Add Wildcard Script Map.
Here we added "*" as Request Path, the full path to the .dll and a friendly name. Under Handler Mappings -> My Handler -> Right click -> Request Restrictions -> Mapping -> Unchecked "Invoke handler only if request is mapped to:".
The handler is now listed under the enabled handlers. Now the web.config got modified:
<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>
But when we execute the page on the website the handler does not seem to work, cause we are not getting redirected to Google. What is wrong here?