HTTPStatusCodeResult无法在localhost上运行的自定义错误消息 [英] Custom error message with HTTPStatusCodeResult not working on localhost

查看:368
本文介绍了HTTPStatusCodeResult无法在localhost上运行的自定义错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器动作,如果验证失败则返回400:

I have a controller action that returns a 400 if validation fails:

return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "My custom message");

在本地运行时,我得到标准的400 Bad Request,而不是预期的400 My custom信息。它在部署的站点上运行正常,在我的旧PC上本地运行时

When running locally I get the standard "400 Bad Request", instead of the expected "400 My custom message". It works fine on the deployed site, and when running locally on my old PC.

这可能是IIS或Visual Studio配置问题吗?我尝试过对旧的和当前计算机的applicationHost.config进行区分,但没有什么明显的。

Could this be an IIS or Visual Studio configuration problem? I've tried diffing the applicationHost.config of my old and current computers but there was nothing obvious there.

响应的图像(无法嵌入):

Images of the responses (can't embed yet):

  • The response from localhost on the new machine
  • The response from the deployed site on the new machine
  • The response from localhost on the old machine

编辑:旧计算机的操作系统是Windows 7,新计算机的操作系统两者都安装了IIS Express 10,项目配置使用。

Old computer's OS was Windows 7, new computer's OS is Windows 10. Both have IIS Express 10 installed, which the project is configured to use.

推荐答案

在dev工具中查看请求透露,行为不端的请求是使用HTTP / 2,以及所有其他变种(新计算机到部署的网站,旧的计算机到localhost,旧计算机到已部署的站点)正在使用HTTP / 1.1。

Watching the requests in dev tools revealed that the misbehaving request is using HTTP/2, and all the other variants (new computer to deployed site, old computer to localhost, old computer to deployed site) are using HTTP/1.1.

来自HTTP / 2规范


HTTP / 2确实没有定义一种方法来携带HTTP / 1.1状态行中包含的版本或原因短语

HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line.

< a href =https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/http2-on-iis =nofollow noreferrer>原因从旧PC转移到新PC时突然出现问题:

And the reason it suddenly became a problem when moving from the old PC to the new one:


HTTP / 2是如何重做的HTTP语义通过TCP连接流动,Windows 10和Windows Server 2016中存在HTTP / 2支持。

HTTP/2 is a rework of how HTTP semantics flow over TCP connections, and HTTP/2 support is present in Windows 10 and Windows Server 2016.

这篇关于HTTPStatusCodeResult无法在localhost上运行的自定义错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆