In ASP.NET, you probably spend most of your time creating .aspx files with .cs files as code behind or use .ascx files for your controls and .asmx files for web services.
A web handler file works just like an aspx file except you are one step back away from the messy browser level where HTML and C# mix. One reason you would write an .ashx file instead of an .aspx file is that your output is not going to a browser but to an xml-consuming client of some kind.
A web handler file works just like an aspx file except you are one step back away from the messy browser level where HTML and C# mix. One reason you would write an .ashx file instead of an .aspx file is that your output is not going to a browser but to an xml-consuming client of some kind.
Working with .ashx keeps you away from all the browser technology you don't need in this case. Notice that you have to include the IsReusable property.
What does the code there do?
It defines two parts of the IHttpHandler interface. The important part is ProcessRequest(), which will be invoked whenever the Handler.ashx file is requested or pointed to.
- <%@ WebHandler Language="C#" Class="Handler" %>
- using System;
- using System.Web;
- public class Handler : IHttpHandler
- {
- public void ProcessRequest(HttpContext context)
- {
- context.Response.ContentType = "text/plain";
- context.Response.Write("Hello World");
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
Using query strings
Developers commonly need to use the QueryString collection on the Request. You can use the Request.QueryString in the Handler just like you would on any ASPX web form page.



mark goldinPosted Jan 8, 2022, 1:19 PM
I am trying to accmplish something like this. I have an aspx page that is called does some processing and returns a html. What I want is to be able to stream a file back from this page but continue normal processing. I can write a file down to the hard drive and have the returned html downloading that file, but will leave a file on the server. I am trying to avoid that. Any idea?
hardik gheewalaPosted Nov 4, 2018, 5:47 AM
Thank you for sharing such a simple artical on us of handlers. Good job..
olivermodePosted Oct 18, 2018, 9:48 PM
Call ashx is like calling a flie, so if the ashx file is locate at "RootFolder\somefolder1\somefolder2\yourhandler.ashx" then in the url you should call "http://localhost:xxx/RootFolder/somefolder1/somefolder2/yourhandler.ashx?aaa=xxx&bbb=xxx"
Angelique CruzPosted Feb 22, 2018, 7:16 PM
Does it possible to call a class/soap function inside a handler .ashx?
Sivaiah DevaraPosted Dec 4, 2016, 2:37 AM
Thank u, it's help to move further step in handler.ashx concept
Santosh Kumar AdidawarpuPosted Jun 2, 2016, 6:11 AM
Nice one
vikas kumarPosted Sep 27, 2011, 11:38 PM
i have stored some .doc and .docx files in binary form in my database . now i want them to retrive back in my browser for that i am using handler.ashx but getting an error. help me out with code snip. thanks
john johnnyPosted Mar 6, 2011, 12:35 PM
simply and clear to understand. Thank you
ClemPosted Mar 15, 2010, 1:20 PM
Another worthless thing Microsoft created just to complicate things. (Like Interfaces).