Reputation: 2634
Looking at my web app, when it is all compiled and ready to be deployed, the folder I have has a bunch of .ASPX and .ASHX files. The ASHX files are of course some custom handlers I made for very specific instances where they could be image handlers or a something else where I didnt want a whole Page class life cycle.
I noticed that .ASPX files have all the HTML content (all the tags) and the .aspx.cs files are compiled into .DLL files (as expected) which is just loaded up into IIS. That is great.
But I also saw that the .ASHX files are just the way they are. All the code is in my .ASHX file and that is the exact same file in the folder deployed to my server. No compiled DLL or anything.
So the question is this: Do the .ASHX files execute slower because it is somewhat of an interpreted file? I know I am probably wrong but there is nothing compiled it seems for .ASHX files and I originally used them for speed. Or is the code compiled once into memory by IIS and kept there for later use? Or is that maybe what the IsReusable bool is property is for?
Upvotes: 1
Views: 7221
Reputation: 25210
They're compiled, so performance won't be an issue.
It is, however, possible to use a code-behind for .ashx
files in the same way as .aspx
files and suchlike. In your .ashx
file:
<%@ WebHandler
Language="C#"
CodeBehind="UserImageHandler.ashx.cs"
Class="Namespace.UserImageHandler" %>
and then in a code-behind:
using System;
using System.Web;
// more here if you need them...
namespace Namespace
{
public class UserImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// etc. etc.
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Doing it this way instead of inline can make life easier if you have lots of code.
Upvotes: 2
Reputation: 3139
As I understand it, the ashx file is a location to request, which simply directs the request to the code behind ( which is compiled as everything else ).
So yes, an ashx file is probably very slightly slower, the first time, as it is compiled on request. But the performance hit is minimal - a simple redirect to a code block.
Upvotes: 0