简体   繁体   中英

No response from ASP.NET HTTP Handler— only on specific HTTP clients on specific machines

I have a minimum ASP.NET Handler (.ashx) that returns a PDF file:

public void ProcessRequest(HttpContext context)
      {

         context.Response.ContentType = "application/pdf";
         context.Response.BinaryWrite(File.ReadAllBytes(context.Server.MapPath("~/files/GettingStarted.pdf")));

      }

      public bool IsReusable
      {
         get
         {
            return false;
         }
      }
   }

When I run my web application on IIS Express, the app is hosted at localhost:45050. If I browse to localhost:45050/handler1.ashx on my main development machine, the PDF is downloaded as expected. If I use the DHC Chrome extension (an HTTP client) to perform an HTTP GET on localhost:45050/handler1.ashx, an HTTP 200 OK response code is returned along with the binary data:

开发人员机器上的DHC响应

HOWEVER, if I run the exact same ASP.NET project on a different machine , I run into bizarre issues. With the project running locally on localhost:45050, I'm still able to browse to localhost:45050/handler1.ashx in Chrome/Firefox/IE to download the file. But, when I use the DHC extension to perform an HTTP GET on localhost:45050/handler1.ashx, there is no response!

在alt机上的响应

I'm able the resolve localhost:45050 (the home page of the site) via DHC on this alternate machine. The server responds with 200 OK and yields the landing page.

But when dealing with the handler that returns binary content, I cannot get any response back from the server with any HTTP client aside from the browser's URL bar. How are browsers able to resolve the HTTP response when standalone HTTP clients cannot? Does anyone have any idea what may be happening here? What would cause behavior to change across machines? I'm trying to handle the response in a JavaScript client, but I'm not getting any data back.

Any help would be greatly appreciated. Thanks!

The top answer here...

Best way to stream files in ASP.NET

...resolved the problem. It seems that writing large files in a single call is a no-no on certain servers. You have to chunk the response manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM