0

Thanks to the published ASP.NET MVC conventions, I'm looking much more closely at the idea of universal conventions over configuration for my projects (versus 'home-rolled' conventions, or grabbing from a variety of conventions).

However, I'm not seeing much, if anything, about the preferred location of ASHX files in, for example, ASP.NET MVC projects (as well as Web forms projects).

Is there a recommended directory structure for these? Perhaps there's a published specification with a much larger directory structure accounted for?

My personal convention has been to place these within a top-level Handlers directory, but I honestly haven't personally seen any other projects that really do this.

I suppose, depending upon what it does (for example, generating an image), that one could argue this might go into the Content directory, but it seems this directory is generally used for static files.

(Aside: One could argue that ASHX files are not needed in MVC projects, but based on questions posted here, it appears ASHX files still have their place in MVC projects.)

EDIT: Ignore MVC projects, since I'm suggesting that as one example. How about Web Forms, then?

James Skemp
  • 8,018
  • 9
  • 64
  • 107
  • Why would you want to use handlers in an MVC project? Surely much better to handle your requirements within the MVC framework. I can't think of a scenario where a handler would be the way to go – Rob West Mar 18 '11 at 13:20
  • Hence the aside :) See, for example, the comments on the accepted answer to http://stackoverflow.com/questions/619697/what-are-the-benefits-of-an-ashx-handler-file-in-asp-net There's others that I've run into the last couple days while researching this. Suffice to say, it seems ASHX files do have some *limited* need in MVC projects. – James Skemp Mar 18 '11 at 13:25
  • Thanks for the linked question - but I'd argue against using a handler in each of the scenarios in the accepted answer. All of them can be handled via MVC in a simple manner. Mixing in handlers just feels messy and retrograde. – Rob West Mar 18 '11 at 13:28
  • I'll grant you that. (And found another I had seen the other day - http://stackoverflow.com/questions/856006/asp-net-mvc-vs-webforms-vs-http-handlers-ashx-which-is-the-most-lightweigh which is in line with what you've said above.) – James Skemp Mar 18 '11 at 13:34
  • Okay. Seemingly my question is getting lost because of my using ASP.NET MVC as an *example* of a project type. How about in Web Forms projects? Any suggestion conventions? – James Skemp Mar 18 '11 at 17:07

2 Answers2

2

My personal convention is to not create handlers as ASHX files, but as classes delivering form IHttpHandler interface. I keep them in separate .dll file and register through web.config.

On the other hand all the scenarios described in question you have linked are easy to achieve within ASP.NET MVC Framework, without additional handlers.

tpeczek
  • 23,867
  • 3
  • 74
  • 77
  • here here. There's just no need for handlers anymore – BritishDeveloper Mar 18 '11 at 14:24
  • Tweaked the question so people aren't getting lost on the example of an MVC project. So separate DLL. You use a single DLL for all of the handlers, or per return type? – James Skemp Mar 18 '11 at 17:08
  • I usually group them by functionality. If I have an API, which will return the same logical result in few formats, I will put all the handlers in one dll. – tpeczek Mar 18 '11 at 20:40
  • [Hear Hear vs Here Here](http://libroediting.com/2011/11/14/here-hear/) OT I know, but I cannot let it stand – Andrina Websdale May 07 '13 at 12:08
1

For ASP.NET MVC projects there's a good discussion about suggested project/directory structure in the question ASP.net MVC project structure .

For Web Forms it seems Are there naming conventions for ASP.NET web application directory structures? suggests that there is no standard (as of 2008).

Community
  • 1
  • 1
James Skemp
  • 8,018
  • 9
  • 64
  • 107
  • 1
    Double Kudos to you for actually trying to answer the question, as opposed to give unwarranted advice about whether or not to use handlers in an ASHX file. – Bryan Feb 24 '15 at 17:46
  • Thanks :) Having not looked at this question in a while I see that some of the down votes on my question were cancelled out. It may not be ideal, but sometimes you just need to use a handler in an MVC project. – James Skemp Feb 24 '15 at 19:48
  • I'm actually using one in a web forms project, trying to block anonymous access of some static content files. I was trying to figure out where to put the handler, and found that the App_Code folder is appropriate for that kind of file. – Bryan Feb 24 '15 at 23:37