How to handle inter-area web service calls from JS in Orchard CMS

I am trying to call a cross-domain web service from an HTML widget. This does not seem to work. He worked perfectly in the same field. I am trying to create a login page in Orchard that can be used to login to my software in a different domain. The web service validates the user credentials and returns a boolean value, which then generates user authentication.

I read that I could use an HTTP handler or another web service (from Orchard's side) to call a web service in another domain, but I'm not familiar with MVC or Orchard to do this. How to add one of them to my Orchard web application?

+6
source share
1 answer

Cross-domain calls from client code in all major browsers do not matter. You can either

  • Use CORS i.e. set the Access-Control-Allow-Origin header to http://your-caller-domain.com in the web service response to allow requests coming from your site’s domain.
  • Use JSONP Technique
  • Create your own proxy API in your application (using a regular ASP.NET MVC controller or WebAPI ) that will make a server-side call using the WebClient class and return a response to you.

Parameters are ordered from best to worst. CORS is supported by most browsers, with the exception of IE8 / 9 (which have partial support through XDomainRequest ) and later. There are workarounds for this.

Please note that the first two are related to the changes on the side of the web service - if you cannot do this, option 3. remains the only one.

+11
source

Source: https://habr.com/ru/post/955208/


All Articles