MessageHandlers vs Filters in asp.net mvc web api project

What is the difference between using MessageHandler and a filter to check the API key in the request header for the MVI MVI web project.

I see that there is a well-described MessageHandler example for this purpose at http://www.asp.net/web-api/overview/working-with-http/http-message-handlers

eg.

GlobalConfiguration.Configuration.MessageHandlers.Add(new ApiKeyHandler()); 

But it looks like I can do the same using a filter.

 GlobalConfiguration.Configuration.Filters.Add(new ApiKeyFilter()); 

Assuming that ApiKeyFilter and ApiKeyHandler just look at the request header and check the api key, which method is more efficient? What's the difference?

+7
source share
1 answer

MessageHandlers work much earlier than filters.

order:

-MessageHandler

-Authorization filter

-Model binding

-Other filters

Security-related things should start as early as possible.

+6
source

All Articles