I want to have control over my Http Exceptions to the point of being able to dictate what is in the body of the response. If I throw a standard HttpException(404, "not found"); then using fiddler I can see the 404 status code is set but there is all this garbage html thats shoved into the response body.

Is there any way to override or extend the HttpException class to allow you to inject your own content into the response body?

I have attempted to implement my own CustomHttpException that like the HttpException extends the ExternalException class but no matter how I cut it the system always throws a 500 error with the same standard html in the body.

Any help?

有帮助吗?

解决方案

No, no, no.

Take a look at CustomErrors.

Basically you do something like this

    <customErrors defaultRedirect="GenericError.htm"
                  mode="RemoteOnly">
       <error statusCode="404"
              redirect="NotFound.aspx"/>
    </customErrors>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top