0

我在执行错误的Web-API的WebAPI控制器错误处理

[HttpGet]  
public UserAccount Get() 
{ 
    throw new HttpResponseException(
     new HttpResponseMessage(HttpStatusCode.InternalServerError) 
    { 
     Content = new StringContent("My Error Message"), 
     ReasonPhrase = "Critical Exception" 
    }); 
} 

处理当我试图从我的机器调用此方法(站点本地托管)一个问题,它是按预期工作。即我收到了错误信息(纯文本)。但是当我从另一台机器(连接局域网)访问相同的URL时,响应是IIS 500内部错误页面。这里我的问题是,我没有得到自定义错误消息“我的错误消息”

有什么建议吗?

回答

1

添加到您的web配置:

<system.webServer> 
    <httpErrors errorMode="Detailed"/> 
+0

固定...谢谢哥们 – Bibin 2013-03-18 10:35:15