Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

asp.net - In IIS7.5 what module removes the body of a 400 Bad Request

I have written ASP.NET (4.0) code that sets the Response.StatusCode to 400 if the data posted to the server is in valid.
I place useful information in the response body in the format that the request accepts header asks for. eg an html message saying "The date field is required...".

In IIS7 (7.5.7600) on Windows 7 I get the correct html response back to the browser.

In IIS7 (7.5.6000) on Windows 2008 I do not get the html body back, but only a text body with "Bad Request" as the content.

Can someone point me to how I change the configuration of the 2008 server to return the body.
Or is there a difference between these versions of IIS?
Maybe a module in the Machine.config?
For example I know (and have had to work around) that the FormsAuthentication module changes a 401 to a 302 even if you do not want this. May be there is a module that stops the content of a 400 being sent.

TIA.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Solution: edited the web.config system.webServer section and set httpErrors existingResponse attribute to "PassThrough" et voilá fixed.
ie:

<system.webServer>
    ...
    <httpErrors existingResponse="PassThrough"></httpErrors>
    ...
</system.webServer>

Well 2 things got me think about this issue:

  1. the classic CustomErrors behaviour because I was comparing localhost with a remote server
  2. the first wouldn't explain how some of my other Authentication 'errors' were getting through intact

I dug around and came across this article on IIS7: How to Use HTTP Detailed Errors in IIS 7.0

It didn't fully pertain to what I found when editing the web.config maybe due me using IIS7.5 but it was enough to get me into the right neighbourhood.

**Also be aware that with IIS 10 now supporting HTTP2, StatusDescriptions that contain text are no longer supported when request upgrade to HTTP2 so if you respond with 400 (Bad Request) this will get stripped to the numeric 400 only. "HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line."


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...