【问题标题】:Moved MVC3 app from IIS 6 to IIS 7.5 - Ajax response value is different?将 MVC3 应用程序从 IIS 6 移至 IIS 7.5 - Ajax 响应值不同?
【发布时间】:2014-04-14 01:35:03
【问题描述】:

我有一个在某些情况下不返回任何内容的操作。在这些情况下,Action 基本上是这样的:

[HttpGet]
[NoCache]
public JsonResult Search(SearchCriteriaModel search)
{
    var searchResults = Searcher.PerformSearch(search); 

    //searchResults == null
    return Json(searchResults, JsonRequestBehavior.AllowGet);
}

这是用 jQuery 调用的:

$.ajax({
    url: "the url",
    type: "GET",
    data: {search criteria},
    success: function(response) {
        /*
            in iis6 'response' === ''
            in iis7.7 'response' === null, causing an error later
    */
    }
});

在 ii6 中,响应是一个空字符串。在 iis7.5 中,响应是 null

为什么脚本会有所不同?

如何配置 iis7.5 以便脚本看到空字符串响应并继续正常工作?

附加 - Visual Studio Web 服务器也返回空字符串。与 IIS7.5 应用程序完全相同的文件夹设置返回 null。

来自 Visual Studio Web 服务器的响应为空字符串值:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 10 Mar 2014 19:22:29 GMT
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 3.0
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Length: 0
Connection: Close

来自 IIS7.5 的空值响应:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 10 Mar 2014 19:22:32 GMT
Content-Length: 0

【问题讨论】:

  • 我感觉这与现在正在发送的 Content-Type: application/json 标头有关。所以现在空响应被转换成一个 null javascript 对象,而不是一个空字符串。你用的是什么版本的jQuery?
  • @StevenV 我同意就是这样。我正在运行 1.7.2,该应用程序有点旧。
  • @StevenV 好像是应用程序池,谢谢查看。

标签: jquery asp.net-mvc iis-7.5 iis-6


【解决方案1】:

将应用程序池从ASP.NET v4.0 切换到ASP.NET v4.0 Classic,将不再发送Content-Type

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 0
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 3.0
X-Powered-By: ASP.NET
Date: Mon, 10 Mar 2014 19:37:28 GMT

【讨论】:

    猜你喜欢
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 2011-12-25
    • 2023-03-27
    • 1970-01-01
    • 2011-07-26
    • 2011-11-30
    相关资源
    最近更新 更多