13

There is an ashx file containing "ProcessRequest(HttpContext context)" method which gets triggered automatically. When and how does it get fired? Another question, How can I get the current QueryString when I am inside this file? When I type "context.Request.QueryString" it says it's null or empty although the address have arguments.

Ahmad Farid
  • 14,398
  • 45
  • 96
  • 136
  • Never had a problem with this - suggest you post your code and your handler config – annakata Nov 03 '10 at 11:54
  • It's a lot of files each function calling another so I am still trying to catch it from the beginning. I guess it's called from some javascript! – Ahmad Farid Nov 04 '10 at 09:25

1 Answers1

27

The ProcessRequest method is called when a request for the ashx file is made. The http context object is passed in to enable access to the stuff like the querystring, headers, etc.

Re: querystring access:

The following will work as long as "ID" is passed on the querystring.

http://example.com/MyHandler.ashx?ID=12345

public void ProcessRequest (HttpContext context) 
{
    string ID = context.Request.QueryString["ID"];
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
HectorMac
  • 6,073
  • 4
  • 24
  • 24
  • Thanks! But how is the request for ashx made? And where usually? – Ahmad Farid Nov 03 '10 at 12:58
  • @Ahmad: What do you mean? The request is made by the client, recieved by the webserver, and passed to the ASP.NET pipeline which hopefully has appropriate web.config to direct the request to your IHttpHandler – annakata Nov 03 '10 at 13:04
  • I mean how does the request to the ashx file look like? I've never used it before and it's not my code. I'm just trying to fix some bug in someone else's code – Ahmad Farid Nov 03 '10 at 13:20
  • @AhmadFarid, do you mean this? `webcam.set_api_url('KameraHandler.ashx?patientID=' + patientID);` – Cute Bear Oct 25 '13 at 05:54