c# - Web API 'Request' is null -


i'm trying return httpresponseexception post web api action using 'request':

throw new httpresponseexception(request.createerrorresponse(httpstatuscode.notfound, "file not in correct size")); 

when doing so, value cannot null. parameter name: request.

essentially - request null.

what missing?

thank you

use this:

httpresponsemessage message = new httpresponsemessage(httpstatuscode.internalservererror); message.content = new objectcontent(typeof(messageresponse), "invalid size", globalconfiguration.configuration.formatters.jsonformatter); throw new httpresponseexception(message); 

note: can change "invalid size" object may want return user. e.g.:

public errormessage {      public string error;      public int errorcode; }  errormessage msg = new errormessage(); msg.error = "invalid size"; msg.errorcode = 500;  httpresponsemessage message = new httpresponsemessage(httpstatuscode.internalservererror); message.content = new objectcontent(typeof(messageresponse), msg, globalconfiguration.configuration.formatters.jsonformatter); throw new httpresponseexception(message); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -