部署 ASP.NET MVC 4 Web API 时出现问题
我尝试部署一个 ASP.NET MVC 4 Web API 站点。一切正常,但如果我从外部调用服务器并返回 400 及以上的 HTTP 状态,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);
}
}
最佳答案
这就是所谓的“智能错误消息”问题。 IIS 劫持了您的错误消息并将其替换为他自己的。典型的解决方法是将 TrySkipIisCustomErrors 设置为 true:
Response.TrySkipIisCustomErrors = true;
关于asp.net - 部署 ASP.NET MVC 4 Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9688118/