i'm developing asp.net webapi application oauth 2.0 authentication separated sts (token service) , custom json formatter (servicestack.text).
i'm trying customize access denied object/message make homogeneous rest of error messages haven't found way change it.
i'm thinking in case used default formatter.
example:
{ "message": "authorization has been denied request." }
example result:
{ "message": "... insert error message here ...", "details": null }
thanks in advance.
you can return custom response current httpactioncontext
using class can define members.
public override void onactionexecuting(httpactioncontext actioncontext) { bool isauthenticated = isauthenticated(actioncontext); if (!isauthenticated) { actioncontext.response = actionexecutedcontext.request.createresponse<customactionresult>(httpstatuscode.unauthorized, new customactionresult { message = "... insert error message here ...", details = null }); } } } public class customactionresult { public string message { get; set; } public string details { get; set; } }