Niraj Trivedi
Niraj Trivedi

Reputation: 2880

IHttpHandler is not getting called on MVC controller action method

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>

Upvotes: 0

Views: 761

Answers (1)

Niraj Trivedi
Niraj Trivedi

Reputation: 2880

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

Upvotes: 1

Related Questions