If you want to replace the default deserialization behavior with custom behavior for a specific DTO request, you can do this in your AppHost installation code:
JsConfig<MyRequestDtoClass>.DeSerializeFn = DeserializeMyRequestDto;
Where DeserializeMyRequestDto
is a function or lambda that takes one string parameter - the body of the raw request - and returns a deserialized instance of your DTO:
MyRequestDtoClass DeserializeMyRequestDto(string rawBody) { ... }
RequestFilterAttribute routines purpotedly access the raw request body using request.GetRawBody()
, where request
is the IHttpRequest
object passed to the Execute
filter method. But in my experience, GetRawBody
returns an empty string because the request input stream seems to be consumed by then due to deserialization. I worked on this once, creating an HTTP module (registered in AppHost via DynamicModuleUtility.RegisterModule
), which will βlookβ into the request input stream in the BeginRequest
event BeginRequest
. (The peek function will read the input stream of the request, and then reset the Position
stream to where it was originally.)
source share