Data List: Extends ContentmentContentContext
to access parentId
Form and JSON data
#389
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Transpires that the client-side patch I submitted for the BlockList editor (in umbraco/Umbraco-CMS#15063), didn't work. This is due to how
ContentmentContentContext
was trying to access theid
andparentId
parameters (on the querystring URL). However, the BlockList editor makes a POST request to theGetEmptyByKeys()
endpoint, but not only that, theparentId
is within a JSON blob sent in the body of the POST request. Which sounds fine, read the JSON from the request body and all good.Not so fast! Turns out that in ASP.NET Core, the
Request.Body
can only be read once, which in the case of theGetEmptyByKeys()
endpoint, that's done with the model-binding (of theContentTypesByKeys
type).So to access the request body contents multiple times, you need to enable
request.EnableBuffering()
. From searching through Umbraco source, I found that there is an extension method calledGetRawBodyStringAsync()
, which even has the.EnableBuffering()
call in it, super, job done.Not so fast! Turns out that
request.EnableBuffering()
must be done at app-startup. Now, I needed a way to add a middleware to configure the request buffering, but I didn't want to enable this for all request (as it's considered a small performance hit), so I wanted to have a conditional middleware for a specific route/path.I found this blog post super helpful in figuring out how to do this:
https://markb.uk/asp-net-core-read-raw-request-body-as-string.html
TL,DR; Contentment adds a conditional middleware to the
GetEmptyByKeys()
API route to enable buffering of the request body contents, so that it can be accessed again during the request lifecycle.Please note, that I have targeted this PR on (upcoming) Contentment v5, as it (currently) only relevant for the BlockList editor patch available in Umbraco v13.1.0. I do not intend to backport it to Contentment v4.6.x, that is, unless there is a good enough reason to do so.
Related Issues?
ContentmentContentContext
to accessparentId
form data (POST requests) #388Types of changes
Checklist