Closed Eudoxe closed 7 years ago
Thank you for a very well prepared question - I love answering these :). Since it's not a bug but just missing something in your work, I'll continue to answer it on your question in StackOverflow.
I wanted to add a context. The call of the webApi SHOULD be done outside of DNN / 2sxc module. We have systems having data and want them to be sent these data to the DNN website. We can't use the $2sxc(mid).webApi.post javascript as we are outside.
So when called from outside, there is an error but when called from inside, there is no problem. Of course, it's the same controller code. Maybe it's something I'm doing wrong in the ajax call but I have a doubt that it is the problem because I receive properly the json sent in the controller and after that, it's the same instructions that are called for building the object that will be sent to the App.Data.Create instruction (the second arg).
May I respectfully ask you to reconsider the problem and can I suggest that you reproduce the problem with the supplied html file without paying attention to the "$2sxc(mid).webApi.post" code that works with my controller correctly?
Thank you very much for your involvement and support!
I'm actually really convinced that my answer in stack-overflow is correct. did you read it? it explains how it works when using 2sxc-controllers from "outside".
I'm submitting a
about
Current behavior When calling a POST method in a controller outside of DNN and a 2sxc application (a stand alone htm file on the computer desktop for exemple), the method App.Data.Create returns a NullReferenceException. However, when the same method is called from a 2sxc template, it works perfectly.
Expected behavior We should be abble to call the WebAPI create function from outside a 2sxc app.
Minimal reproduction of the problem with instructions 1/ Create a new app "
gouvGouvernement
". Add a content Type "Organismes
". Add 2 string fields "Nom
" and "Acronyme
" 2/ Create a controller file "api/gouvGouvernementController.cs
". Code below 3/ Create a htm file on the computer desktop. Code below 4/ Load the htm page on Chrome or other browser 5/ Go to the admin log. You should see the exception and of course no item added. 6/ Create a template. Add the code bellow. 7/ Click on the link. The new entry should have been added.< ================================================== >
gouvGouvernementController code
< ================================================== >
htm file
< ================================================== >
Code in a template
< ================================================== >
Stack errors 2 significative errors are logged in DNN:
and an admin alert (which is not really revelant):
What is the motivation / use case for changing the behavior? External systems should be able to send their data to an application via webAPI POST
Please tell us about your environment: Azure application
Anything you would like to add This is the same problem reported on StackOverflow https://stackoverflow.com/questions/46476657/2sxc-method-app-data-create-returns-system-nullreferenceexception