This topic is locked
[SOLVED]

API call returns System.Web.MvcRedirectResult not a json.....

1/22/2023 5:31:16 PM
ASPRunner.NET General questions
D
david powell author

Hi,
I have asprunner.net 10.8.
REST API is enabled with basic authentication.
I have sucessfully retrieved data from tables in other apps, but with my current application, trying to retrieve a small dataset from a simple table, the API is returning

System.Web.Mvc.RedirectResult.

This appears to be coming from asprunner, as even going to a browse and inserting the appropriate URL and then entering the username/password in the resulting authentication challenge still returns the same message.

The api call looks like

http://rxtracker.co.uk/api/v1?table=matchingpatients&action=list&q=(postcode~equals~BA68NS

Firefox developr returns RAW data of 'System.Web.Mvc.RedirectResult.' fromt his.

I cant find any settings on asprunner to force data to be returned rather than a redirect .... can anyone give me some pointers?

DAvid

D
david powell author 1/23/2023

I have determined if the target server has no authentication set up, the result returns as data in a json.
As soon as I enable basic authentication, it returns a redirect.

So for example - without any authenication the url above when inserted into a browser returns a dataset.

  • turn on authentication and provide the correct login details on the challenge on the same browse and a redirect message is returned.

In the requesting app ( which is for an android device) I have set follow redirects to no avail.

How can I get asprunner to return the data and not a redirect - or where is it redirecting to?

D
david powell author 1/24/2023

I think I might have solved it. Its because after an authenticated login it runs code in my website in the aftersuccessfullogin event.
I am recreating an empty site specifically for api with no code, and hopeful it will work!

It does talk about api calls failing if there are events that interfere with it on logging in in the user guide, just had to find it!

M
MikeT 1/24/2023

maybe you just need to check if the request is just a REST request or a regular one via https://xlinesoft.com/phprunner/docs/rest-api-inrestapi.htm

D
david powell author 1/31/2023

It was the post successful logon event that included a redirect and the API call coulnt get past..
Solution was to create an ASPRunner site that is purely for API calls, with authentication and the required queryies but no code.

M
MikeT 2/1/2023

That's great.
I'm on phprunner not asprunner, so I hope I'll be able to detect this in AfterSuccessfulLogin, have a project upcoming where I wanted to use that....