c# - Why is Http code 500 returned although I catch the exception -


although if-clause executed in fiddler see http error 500 , not 404, why that?

public class globalexceptionhandler : exceptionhandler     {         public override void handle(exceptionhandlercontext context)         {             if (context.exception resourcenotfoundexception)             {                 context.request.createerrorresponse(httpstatuscode.notfound, context.exception.message);             }             else             {                 base.handle(context);              }         }     } 

this in fiddler response:

http/1.1 500 internal server error content-length: 3945 content-type: application/json; charset=utf-8 server: microsoft-iis/7.5 x-powered-by: asp.net date: wed, 08 jul 2015 08:14:45 gmt  {"message":"an error has occurred.","exceptionmessage":"the resource not found!","exceptiontype":"erpapplicationendpoints.resourcenotfoundexception","stacktrace":"   @  ... removed clarity... 

you need set result property on exceptionhandlercontext object in if clause instead of doing createerrorresponse(also incorrect not assigning created httpresponsemessage anything)

context.result = <a-httpactionresult-instance-here>


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -