在IIS中启用https时,错误的请求错误返回“错误”,而不是错误消息

问题描述 投票:0回答:1

我有一个IIS 10.0上托管的ASP .NET MVC 4网站。控制器中的操作方法将验证输入,如果输入不正确,则该操作方法将返回错误请求状态代码(400)和错误消息。此代码如下所示

public ActionResult SaveCustomer(Customer customer){
      var message = string.Empty
      var isValid = ValidateCustomer(customer, ref message);
      if (!isValid)
      {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest,message);   
      }
      //Remaining code to save customer
}

客户端代码使用JQuery AJAX请求,如下所示

var customer = {};
// Code to fill the customer object
$.post('/customer/savecustomer', customer, function (data) {

            alert('Customer saved');

        }).error(function (response) {
            alert(response.statusText);

        });

response.statusText将显示在操作方法中设置的错误消息,只要该站点使用的是http。但是,一旦使用https配置了站点,则response.statusText仅返回“错误”。我尝试使用此处提到的解决方案,但它不起作用。ASP.NET MVC 5 ajax error statusText is always "error"

[当我在Chrome开发者工具中打开“网络”标签时,发现以下内容:

启用HTTP时

  • 标题标签

    请求网址:http://example.com/Customer/SaveCustomer

    请求方法:POST

    状态码:400 从服务器发送的错误消息

    远程地址:xxxx.xxxx.xxxx.xxxx:80

    推荐人政策:降级时不推荐人

  • Response tab

    错误请求

启用HTTPS

  • 标题标签

    请求网址:https://example.com/Customer/SaveCustomer

    请求方法:POST

    状态码:400

    远程地址:xxxx.xxxx.xxxx.xxxx:443

    推荐人政策:降级时不推荐人

  • Response tab

    错误请求

http和https之间的区别在于,错误消息返回的状态代码带有http,只有状态代码的返回https。

任何想法?

c# jquery asp.net-mvc https bad-request
1个回答
0
投票

证明它与HTTP 2.0有关。我关闭了HTTP 2.0并切换到HTTP 1.1。现在,错误消息显示如预期的那样。我不知道为什么HTTP 2.0会导致此行为。

© www.soinside.com 2019 - 2024. All rights reserved.