Razor Page, object list prop losing all members between RedirectToPage and the OnGet call - razor

I'm using the Xero API to do some calculations on employees. This requires an OAuth2Token, specifically the tenantId and the accessToken. This is gotten by redirecting the user to log in and then providing them with the token
The tenantId is a generic list of Tenant. I grab the token through API means and then I assign it to a variable as a XeroOAuth2Token.
Then I send it as the route value. Using breakpoints I can see that the variable looks fine as it is sent to RedirectToPage.
Yet the immediate OnGet that is called, everything is the same except the TenantList no longer has any members?
The solution to this is to serialize the object and send it as a prop inside an anonymous object, I want to know why I have to do that. Thank you for any insight

Related

JSON object losing info between API call and Frontend

I'm making a website that gets its info from a RESTapi I've written and hosted myself, have had no data problems thus far.
Now I'm trying a simple retrieve of a json object and I get all the info correctly as shown here in the API. (Visualized & tested in Swagger)
As you can clearly see, it retrieves it the complete object and underlying objects correctly (blurred sensitive info).
Pay attention to the property "AmountOfEggs" though.
Now when i call this api endpoint (exactly the same way) in my site and console.log the result.data, this is the feedback.
Now for some reason I can't recieve AmountOfEggs in my frontend.
I've recreated the entire object, wrote different names, passed different props (Id, NumberBus, etc are passed in this situation with no problem, which are also int (number) types).
I have no idea why this property gets "dropped" in the transfer and filled with/defaults to an empty string.
Any help would be greatly appreciated.
I found where it went wrong and it's due to different factors.
To start, I am making this site using the Vue framework, which has reactive components, which means, data gets adjusted and you get live updated components on your views/pages.
In the page that contained the call, I also wanted to add dynamic styling. The code I used for this is the following:
v-for="seller in retrievedSellers"
:key="seller.Id"
:class="[
'sellerStyle'
, (seller.AmountOfEggs = 0 ? 'grey-out-seller' : ''),
]"
Now two things to note, first of all this might look like backend coding but this is Vue logic on the .vue file which handles the dynamic options that Vue provides so I never thought to look here for the error.
The error of couse is the 'seller.AmountOfEggs = 0' part, using one equal sign (assignment) instead of two (comparison).
So I learned,
Vue doesn't throw errors on assignments in code that is used to generate frontend (where you should NEVER alter your data).
My console.log was the moment the response of the API came in, where apparently it was already assigned a new value (due to my code above) before hitting the console.log.
It still greatly surprises me that Vue handles ^this^ first to make sure your reactive components are up to date before finishing the api call itself.
However, I still don't understand how it said "" instead of 0.
I'm using typescript (javascript strongly-typed) so it definitely wants to contain a number and not an empty string. Even in the declaration of my DTO the property is defined as (and expects) a number.

How to store action result and pass as http header

Currently I'm trying to create a simple login form with Microsoft PowerApps.
I have a login action (Web API2) that is called:
SampleAPI.AuthLogin({UserName:UserNameTextBox.Text, Password:PasswordTextBox.Text})
This is working great. The Login method is returning a json web token which should be passed in all following requests. Is this possible?
Futhermore, when clicking on the Login button, a new screen should appear. (Using Navigate).
So how can I set the result of AuthLogin as the Authentication Header in all following http requests?
Thank you very much!
Yes, this is possible. I'm not sure what aspect of what you are trying to do is causing you grief.
I'm going to guess it is holding on to the json web token that is returned. I'm guessing you would like the equivalent of a global variable to hold this value? PowerApps does not have global variables, but it does have global collections. Use the Collect function to store the value in a collection that you can then access from anywhere in the app. You can view collections in your app with the File menu.
If you don't need a global variable, as a variable scoped to the screen will suffice, then you can use a context variable instead.

ASP.NET WEB API PUT method Nullreference Exception

I'm trying to pass an object named "User" with user data in HTTP PUT method. I've created a custom controller method, gave it a [HttpPut]. In my application i'm calling a proper route with PUT header, but when i'm trying to pass an User object in JSON format my WEB API is throwing nullreference exception, which indicates that user object isn't passed. MY other custom POST methods are working fine, I'm having problem only with PUT method. My object in JSON format has proper formatting, I double-checked. What may be causing the problem?
I managed to fix the problem. In my User model constructor i deleted initialization of lists of other objects and it worked.

zf2 json view script

We are currently trying to set up routes in such a way that the returned content-type can be set using a route parameter. The routing is all working properly now, but there is one problem. If one requests html, then the normal view script is rendered. The data we provide to this script can be anything from a string to a collection of objects, and the view script decides what to show to the user.
If however JSON response is requested, then we just provide the data returned from our controller as JSON. However, some data should not be made publicly available to the user, and hence some filtering is required. Is there any possibility to use JSON view scripts (as in ZF1 with context-switch) in order to support such filtering? Or maybe another method?
There is no such thing as a JSON script which lets you decide what to render and what not. You have to provide the proper data in the view model such that only the data is given that is eligible to be displayed.
I have been thinking about a hook in the JSON renderer so you can filter the view model's data based on the context of the request, but such thing does not exist yet. Unfortunately, you have to select the data in your controller or model.

questions wcf rest service with webclient

I'm getting confused on a few things in regards to wcf rest.
If you call a login method, should I use a POST or GET? After implementing a POST, I started to find various articles saying you should only use post to update data, and get for retrieving data. Which is the most appropriate method?
If I had to change the Login method from a Post to a Get, how would I call this?
http://....myservice.svc/login/{username}/{passpord} or is there another way to call this?
Note that in my post method, I'm passing and returning data in json format.
I need to create a search function that requires to pass various parameters i.e. list, string, list, etc... I assume in this instance I would have to define GET method, but again how to I pass these list of objects? Convert them to json first and pass them as parameters?
A brief url sample would be great.
Ok, I guess I'll answer my own question based on further finding when researching it and remember that my answer is based on using JSON as parameters. I'm not sure how it would behave if xml was used as I did not try it.
It appears to make more sense to use POST when logging in as you do not want to display the information you are posting via a url. You could encrypt the data and pass it in the url using a GET method... Again I could be wrong, but that's how I interpreted the various articles I read.
Again, in this instance, it appears POST is the best solution if a) you require a large amount of data to be passed to your url and b) if you do not want to show this data to the user. If your query only requires simple parameters (i.e. userid, type, etc...) and you don't mind showing this info, you can use the GET method.
If you require to pass multiple parameters to a function, you should instead pass a single parameter. This parameter should be a single object. This object should be made of all the parameters you wanted to use in the first place, this way, when using the POST method, this object can easily be converted to JSON and it will handle passing multiple parameters through a single object and it will handle numeric, string, list<>, array<>, etc... very nicely.