0

I have a http handler which is registered and working fine. Now i want to process a request, and send a custom html response which is then shown on the client.

So my function is written as follows:

public void ProcessRequest(HttpContext _context)
{
    HttpResponse response = _context.Response;

    response.Clear();
    var requestedUrl = _context.Request.Url;
    PhantomModuleController pmc = new PhantomModuleController();
    response.BufferOutput = true;
    var snapshot = pmc.DoThings(requestedUrl); //this returns a string
    response.Write(snapshot); //i put it in the response
    response.ContentType = "text/html";
    response.End(); //it should send it to the client now
}

But according to my fiddler, the response never arrives on the client. In fact, the httpresponse is never even sent.

Did i forget somethiing

Taylan Aydinli
  • 4,333
  • 15
  • 39
  • 33
Henk Jansen
  • 1,142
  • 8
  • 27

1 Answers1

1

Because the request is not showing up in Fiddler as being sent back to the client (nor an error back to the client), the routing engine may be getting in the way of the request. The scenerio is described by phil hack.

However, there are other cases where you might have requests for files that don’t exist on disk. For example, if you register an HTTP Handler directly to a type that implements IHttpHandler. Not to mention requests for favicon.ico that the browser makes automatically. ASP.NET Routing attempts to route these requests to a controller. One solution to this is to add an appropriate ignore route to indicate that routing should ignore these requests. Unfortunately, we can’t do something like this: {*path}.aspx/{*pathinfo}

You need to setup the route engine to ignore the route that has the file extension. E.G.

routes.IgnoreRoute("{*allaspx}", new {allaspx=@".*\.aspx(/.*)?"});
routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348