i am trying to write out a response to the client:
response.StatusCode = (int)HttpStatusCode.BadRequest;
response.ClearContent();
response.Write(String.Forma
Have you checked that asp.net is enabled on the server? You need to use the Windows server manager to check the features have been installed.
I've just tried your code on my server & despite what I assume is a typo around casing of response
, it worked as expected.
I ran into this exact issue & spent a few frustrating hours today noodling through it. In my case, I am sending potentially very large CSV data directly down to the client via Response.Write and flushing it every 3k records or so. It works great from my local environment, but failed when deployed to IIS 7.5 on a Windows 2008 server. No exceptions, just an empty CSV at the client.
Turns out Dynamic Compression was enabled for my application. It can be disabled via web.config directly, or in your IIS MMC interface. You can validate this by using your browser's tools to examine the headers of the response you're receiving.
Content-Encoding:gzip
Disable dynamic compression (not sure how/why it was enabled originally), and it worked fine. It might not be your issue, but it was mine. I fished around for most of the day on this one and didn't see it answered directly, so I figured I'd throw it out there. Also, the size of the result set didn't matter; a 5kb file & 3Gb file had the same problem.
By default, IIS 7 will change the response if the code is >= 400 http://msdn.microsoft.com/en-us/library/ms690497(v=vs.90).aspx
But you can change this in the httpErrors
element of system.webServer
.
<httpErrors existingResponse="PassThrough" />
EDIT: this will break CustomErrors
, if you are using that. You might be better off returning a 400 without a response, then setting up web.config to redirect to a custom page for 400 errors.
<customErrors mode="On">
<error statusCode="400" redirect="Frobber.htm" />
</customErrors>