简体   繁体   中英

WebAPI Controller error Handling

I have a issue in implementing Error handling in 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. Here my problem is that, I am not getting the custom error message "My Error Message"

Any suggestions?

Add this to your web config:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM