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.
-
Hi, I suggest you to first read the concept of cross-origin requests: 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: stackoverflow.com/questions/6290053/…. Keep in mind that enabling all sources might make your page vulnerable to dangerous scripts.Samuil Petrov– Samuil Petrov2017年06月22日 11:39:02 +00:00Commented Jun 22, 2017 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– MeMySelf2017年06月22日 11:45:23 +00:00Commented Jun 22, 2017 at 11:45
-
Hello @MeMySelf, did you created a Web API project? or it is only an MVC project?Mohamad Dbouk– Mohamad Dbouk2017年07月07日 12:21:17 +00:00Commented Jul 7, 2017 at 12:21
1 Answer 1
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.