Domanda

I have an action that returns nothing in certain circumstances. The Action in essentially like this in these cases:

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

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

This is invoked with 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
    */
    }
});

In ii6 the response is an empty string. In iis7.5 the response is a null.

Why am is the script seeing a difference?

and

How can I configure iis7.5 so that the script sees an empty string response, and continues to work properly?

Additional - The visual studio web server returns the empty string as well. The same exact folder setup as an IIS7.5 application returns the null.

The response from the visual studio web server with the empty string value:

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

The response from IIS7.5 with the null value:

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
È stato utile?

Soluzione

Switch the application pool from ASP.NET v4.0 to ASP.NET v4.0 Classic and the Content-Type will no longer be sent:

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top