0

I have defined a custom HTTP handler, to update the request header. But when I am calling http://localhost:52705/Home/Index. my custom HTTP handler is not getting called for that controller -> action request. I implemented as follow

public class TestHandler :  IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        return;
    }

    public bool IsReusable { get; private set; }
}

also, find the web.cofing entry for HTTPHandler

<system.webServer>
    <handlers>
      <add name="TestHandler" type=" mvc_app.Handler.TestHandler" path="*" verb="*"/>      
    </handlers>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>
Niraj Trivedi
  • 2,370
  • 22
  • 24
  • does it called somewhere else? the `path="*"` is a bit tricky. since handlers are **endpoint**, process requests and done with it. – Bagus Tesa May 31 '18 at 02:10
  • Register your handler in `` under `` – Chetan May 31 '18 at 02:28
  • @BagusTesa I don't know what should I provide in path="*" as we need to call HTTP handler on MVC controller action method – Niraj Trivedi May 31 '18 at 03:32
  • @ChetanRanpariya Thanks I did the same but I am getting HTTP Error 500.23 - Internal Server Error - Module ConfigurationValidationModule Notification BeginRequest Handler ExtensionlessUrl-Integrated-4.0 Error Code 0x80070032 – Niraj Trivedi May 31 '18 at 03:35
  • https://stackoverflow.com/questions/4209999/an-asp-net-setting-has-been-detected-that-does-not-apply-in-integrated-managed-p – Chetan May 31 '18 at 03:54
  • @ChetanRanpariya Thanks I found a solution please check it out my answer – Niraj Trivedi May 31 '18 at 07:26

1 Answers1

1

After spending one day if found one trick to achieve the same functionality as I want to implement using IHttpModule

Add custom HTTP module

public class TestModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.BeginRequest += OnBeginRequest;
    }

    static void OnBeginRequest(object sender, EventArgs a)
    {
        Debug.WriteLine("OnBeginRequest Called MVC");        
    }

    public void Dispose()
    {
        throw new NotImplementedException();
    }
}

Update web.config to register custom HTTP module

<system.webServer>
    <modules>
      <add name="TestModule" type="mvc_app.Handler.TestModule"/>          
    </modules>
 </system.webServer>

for the above solution still, I am trying to figure it out why my OnBeginRequest() method is getting called twice

Niraj Trivedi
  • 2,370
  • 22
  • 24