0

I am building an MVC4 application, where I have the normal MVC views and I have added a few WebAPI controllers. I know that the corresponding controllers exist in different namespaces (System.Web.Mvc and System.Web.Http).

So, I want to create a custom controller which will capture all incoming calls (to webpages and to WebAPI), register the call and perform authorisation, all in one class for consistency.

Is there a MVC way to do that? If this cannot be done with 1 custom controller, is there any other approach to this? Would a HttpModule be a good idea for an MVC application?

Right now, I have created 2 similar classes which derive from: System.Web.Http.ApiController and System.Web.Mvc.Controller but does not seem like a good idea, as I almost duplicate the code.

spiros
  • 369
  • 4
  • 11

2 Answers2

0

I think that for this pourpose is better to use global filters. But you will need slightly different implementations for Mvc and WebApi

See some examples here: How to add global ASP.Net Web Api Filters?

0

The easiest way to implement such functionality is to create a custom HttpModule and register it with Http Pipeline.

You can find the reference to Custom HttpModule and Registration process here

Gururaj
  • 539
  • 2
  • 8