IIS7 不会因错误请求返回 HTTP 400
我有一个 MVC2 站点,我们在该站点上执行了大量集成测试。最重要的是,我们测试了使用错误网址时的行为。例如:
http://xxxx/v1 //Dy888/1/1234567815/swlocation?fv=24&sv2=3&sv3=5
(注意“v1”后面的两个斜杠。)
这应该会产生 HTTP 400、错误请求,并且在开发中环境(VS2008)一切按计划进行。但在测试环境中,IIS7 或 MVC2 会以某种方式看穿这一点并做出响应,就好像只有一个斜线一样。它似乎太“聪明”了,通过重写请求来帮助我们。
如何将我的服务器配置为不“智能”,并真正以正确的错误进行响应?
测试服务器是带有IIS7的Windows Server 2008。
谢谢! - 尼克拉斯
I have an MVC2 site that we perform a lot of integration tests on. Most significantly, we test the behaviour when using bad urls. For instance:
http://x.x.x.x/v1//Dy888/1/1234567815/swlocation?fv=24&sv2=3&sv3=5
(Note the two slashes after "v1".)
This should yield a HTTP 400, Bad Request, and in the development environment (VS2008) everything works as planned. But on the test environment IIS7 or MVC2 somehow sees through this and responses as if there were only one slash. It seems to be too "smart", and helps us by rewriting the request.
How can I configure my server to not be "smart", and to really respond with the correct error?
The test server is Windows Server 2008 with IIS7.
Thanks!
- Niklas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http状态码400定义如下:
URI 中存在额外的正斜杠(仅是整个请求的一部分)不能正确地归类为请求的语法错误,也不会导致无法满足请求,因为额外的正斜杠不会更改 URI 指向的位置。
我认为你的开发网络服务器是行为错误的服务器,并且你的测试的前提是错误的。
The http status code 400 is defined as follows:
Having an extra forward slash in the URI (which is only a part of the request as a whole) cannot rightly be classified as a syntax error of the request, and nor does it make it impossible to satisfy the request, since the extra forward slash does not change the location pointed to by the URI.
I think that your development web server is the one behaving wrongly and that the premise for your test is wrong.