Bibin
Bibin

Reputation: 225

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. i.e 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?

Upvotes: 0

Views: 969

Answers (1)

Admir Tuzović
Admir Tuzović

Reputation: 11177

Add this to your web config:

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

Upvotes: 1

Related Questions