0

I´m working on an ASP.NET MVC project, that does the following:

Users collect data using an android app, this data is being sent as json. This app is under development by someone else, not me, but we´re in contact.

I created a JSONController with the following action:

    [HttpPost]
    public JsonResult PutJSON(JSONModel json){
        // do something
    }

My JSONModel only contains a public string LastName for testing purposes.

For now, I can only publish the project to IIS on localhost, which can be accessed from other devices in my home network. As far as I know, that should be okay for testing, right? The project is accessible and works when entering the ip of that machine in a browser on another device in network.

Is there anything else I need to do in my ASP.NET MVC project to make it accept AJAX calls from "outside"? Am I missing something?

I tried to test with a simple AJAX call from another device, but that´s just giving me internal server errors, because of cross domain call. Accepting those cross domain calls didn´t work though (do I need this when the project is finally being published?)

I´d be very thankful if someone could help, maybe by providing a link to a tutorial explaining how to configure ASP.NET project to accept AJAX calls from the internet.

MeMySelf
  • 1
  • 1
  • Hi, I suggest you to first read the concept of cross-origin requests: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing and then you can refer to this topic to configure asp.net properly to accept your desired requests: https://stackoverflow.com/questions/6290053/setting-access-control-allow-origin-in-asp-net-mvc-simplest-possible-method. Keep in mind that enabling all sources might make your page vulnerable to dangerous scripts. – Samuil Petrov Jun 22 '17 at 11:39
  • I followed the instructions before already, but that didn´t solve my problem. Enabling CORS for certain origins is not what I need for that project when sending json from an app, right? – MeMySelf Jun 22 '17 at 11:45
  • Hello @MeMySelf, did you created a Web API project? or it is only an MVC project? – Mohamad Y. Dbouk Jul 07 '17 at 12:21

1 Answers1

0

Please take a look in the following question:

How to pass JSON POST data to Web API method as object

How to receive JSON data on WebAPI backend C#?

How to receive JSON as an MVC 5 action method parameter

How to receive JSON in asp.net web API?

Hope these will help you.

Ester Kaufman
  • 708
  • 10
  • 20
  • I did read that posts before, too ;) Basically I just need to know if it is enough to have my Action like shown above for accepting AJAX calls from the internet. It works perfectly when sending a call from View with jQuery. – MeMySelf Jun 22 '17 at 12:09
  • Can you please check if you can reach your site pages from where you're trying to access the action? – Ester Kaufman Jun 22 '17 at 12:27
  • The pages (and IIS and so on) are running on my local workstation, and are accessible from devices in my network. From a view on my workstation I can pass json to my action, but from any other device in network that isn´t possible. – MeMySelf Jun 22 '17 at 15:14