HTTP handler vs HTTP module

后端 未结 8 1420
粉色の甜心
粉色の甜心 2020-12-02 04:21

Can someone explain in less than 2 sentences the difference between both? Yes, I know google can provide hundreds of answers but not one in 2 clear sentences:)

8条回答
  •  不知归路
    2020-12-02 04:46

    The two sentences:

    An HttpModule will execute for every request to your application, regardless of extension, and is generally used for things like security, statistics, logging, etc.

    An HttpHandler is generally associated with a specific extension, and is used for things like RSS feeds, dynamic image generation or modification, and the like.

    A little more explanation if that's not completely clear:

    The way I think about them - modules "plug in" to the request pipeline, whereas handlers "handle" a specific file extension. So, if you've got a site with a LoggingModule and a PdfHandler, both will execute for a request to http://example.com/sample.pdf, and the logging module alone will execute for a request to http://example.com/page.aspx.

    There's a pretty clear article on the difference on MSDN: HTTP Handlers and HTTP Modules Overview

提交回复
热议问题