-1

I am trying to figure out the difference between httphandler and httpmodule.

In the article mentioned below it says

CodeProject

our application needed URL rewriting and HTTPHandlers are a bad solution for that and should never be used for that.

This confuses me.

what does it mean? and it shows how to rewrite a url using httpmodule.

  1. So what if i used httphandler to rewrite the URL?
  2. what is it's drawback?
  3. In which scenario i can make use of httphandler?
  4. It says httphandler is used to handle MIME types. So the same problem will not occur (in Post back) for this case?

reference

Can anyone share some real time example of when to use httphandler and httpmodule efficiently?

Tom Cruise
  • 1,395
  • 11
  • 30
  • 58
  • Duplicate of http://stackoverflow.com/questions/6449132/http-handler-vs-http-module – Craig W. Nov 19 '15 at 15:20
  • 1
    @CraigW. I already read that link mentioned. But my question is whether anyone can give a clear explanation of what written on the link that i provided in the question. All the articles says httphandler =>MIME types, extension . httpmodule=> adding additional task for each request. But in the codeproject link , the line mentioned is bit confusing. i am attaching image for reference. The same question asked in the comment too. but the author not responded. – Tom Cruise Nov 19 '15 at 15:32
  • I think why author of above article thinks that Httphandlers are bad idea for Url Rewrite is because only way to rewrite the Url from Httphandler is to transfer request to another handler via Server.Transfer while from an HttpModule you would do ReWritePath(), difference between Server.Transfer and ReWritePath is well covered at http://stackoverflow.com/questions/336813/server-transfer-vs-context-rewritepath – pateketu Nov 19 '15 at 15:54

2 Answers2

1

Think of HttpHandler as the "End Point" of a Request Pipeline in ASP.NET. If you want to handle a request for files ending in say ".ext" then you would right an HttpHandler and respond with whatever is needed.

While HttpModule is the Request Pipeline itself, if you need to modify something during the request or response you do it in HttpModule, so Url Rewriting would fall into that category

pateketu
  • 451
  • 2
  • 8
  • I think handling request with the files ending with .ext also fall under the category of url rewriting..Please correct me if not. – user1357872 Nov 19 '15 at 15:40
  • 1
    no handling a file with .ext wouldn't fall into Url Rewriting. Url Rewriting is basically changing the Url, that technique is used heavily in Searc h friendly Urls. Wherein a Request coming in will have a url of say http://...../product/1 and HttModule will rewrite the internal Url to Product.aspx?Id=1 and let the default handler for ".aspx" extension handle the request – pateketu Nov 19 '15 at 15:44
1

So what if i used httphandler to rewrite the URL?

Then you're re-inventing the wheel. I don't believe there is any reason to rewrite the URL Rewrite module.

what is it's drawback?

I'm pretty sure an HttpHandler can't do everything the URL Rewrite can, nor has it been unit-tested, nor used my millions of people around the world.

In which scenario i can make use of httphandler?

If you need to write legacy code. Modules implement the IHttpModule interface, which is defined in System.Web, and that library is not part of the new ASP.NET.

It says httphandler is used to handle MIME types. So the same problem will not occur (in Post back) for this case?

Otherwise this really is a duplicate of the quesiton HTTP handler vs HTTP module where the answers there are really the best answers.

Community
  • 1
  • 1
Erik Philips
  • 53,428
  • 11
  • 128
  • 150