部署ASP.NET MVC 4 Web API的問題部署ASP.NET MVC 4 Web API
我嘗試部署ASP.NET MVC 4 Web API站點。一切工作正常,但如果我從外部調用服務器並返回HTTP狀態400和以上,Web服務器接管響應。
在服務器本地調用工作正常。
例子:
Work fine:
http:// myTestServer.se/Test/api/Test/200
http:// myTestServer.se/Test/api/Test/399
Does not work, the Web server takes over the response:
http:// myTestServer.se/Test/api/Test/400
http:// myTestServer.se/Test/api/Test/599
For those cases where there is an Error Pages is returned. For an invalid code is returned 」The custom error module does not recognize this error.」
if I make the calls locally on the server, it works fine:
http://localhost/Test/api/Test/400
http://localhost/Test/api/Test/599
我簡單的測試代碼將返回接收到的ID作爲HTTP狀態..
// GET /api/values/200
public HttpResponseMessage<string> Get(int id)
{
try
{
HttpStatusCode StatusCode = (HttpStatusCode)id;
return new HttpResponseMessage<string>("Status Code : " + StatusCode.ToString(), StatusCode);
}
catch {
return new HttpResponseMessage<string>("Unable to convert the id", HttpStatusCode.OK);
}
}
爲了能夠讓您的Web服務器和本地操作相同,請將IIS errorMode設置設置爲自定義而不是DetailedLocalOnly(這是默認設置)。看到這個網站關於它的設置http://www.iis.net/configreference/system.webserver/httperrors – 2014-03-18 19:00:18