Search code examples
c#asp.netashx

Is it a bad idea to use ASHX for an entire website?


I made multiple website in the past using HTML or Perl. I am now looking to use ASP.Net since it allow me to use a language that I am more comfortable with (C#).

I made some experiments with the aspx pages and it seems like they always add viewstates and add an extra request to the server from my current understandings.

I am just looking to have something that will have the ability to use POST/GET data like any ordinary webpage + the ability to use c#.

Currently, I am thinking about making the entire website using the ashx format since it seems like the format that is the closest to fullfill these needs. This would imply that I would probably need to create a custom template manager to print mix of static html content and generated content.

Does it sound like a bad approach? I don't need a system (aspx) that will add weight to my pages and slow down the process if I already handle everything using POST/GET requests no?


Solution

  • ASHXs are basically handler pages. In a webforms-laden site, ASHXs were often used for one-off JS calls, image handler, or to basically fill that niche where you wouldn't normally create a full-on ASPX.

    From what you describe, your aim is to create lightweight pages where you have a bit more control, and it sounds like what you need is ASP.NET MVC.

    Further, depending on what you're actually doing, you should look at ASP.NET MVC for web pages. If you're simply creating an API, then have a look at ASP.NET WebAPIs instead. Both paradigms are very similar to each other, take care of a lot of management for you and are not considered legacy (as of the time of writing anyway)

    To answer your question more directly - it may not be entirely bad to use ASHX for a few endpoints that you need to compliment something else, but it can certainly become bad as the scope of the application increases over time and you add more and more pages. You end up with a monolithic 'page' structure repeating itself over a project, which may not be conducive to maintenance; whereas with the MVC approach you will at least have the structure in place for some quality control and separation. ASP.NET MVC already gives you the separation, templates and control over your pages, so it is a good fit.

    tl;dr - yes, it's a bad idea.