[英]WebAPI Controller error Handling
I have a issue in implementing Error handling in Web-APi 在Web-APi中实施错误处理时遇到问题
[HttpGet]
public UserAccount Get()
{
throw new HttpResponseException(
new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent("My Error Message"),
ReasonPhrase = "Critical Exception"
});
}
When I tried to call this method from my machine(site is hosted locally), it is working as expected. 当我尝试从我的机器(站点托管在本地)上调用此方法时,它正在按预期方式工作。 ie I got the error message in response (plain text).
即我得到了错误信息作为响应(纯文本)。 But when I access the same url from another machine(LAN connected), response is IIS 500 internal error page.
但是,当我从另一台计算机(连接局域网)访问相同的URL时,响应是IIS 500内部错误页面。 Here my problem is that, I am not getting the custom error message "My Error Message"
这是我的问题,我没有收到自定义错误消息“我的错误消息”
Any suggestions? 有什么建议么?
Add this to your web config: 将此添加到您的Web配置:
<system.webServer>
<httpErrors errorMode="Detailed"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.