Why do I get a 403 ban when I call an external IIS-based MVC that returns a JSON result

I have an application that was provided by a third party. The only way to change the behavior is the client side of the script. I have a screen in the application that makes some special requests, but does not provide any means to save the settings. Instead of entering user parameters each time, I entered some elements through jQuery so that they can save their queries.

I have another internal site, which is asp.net MVC, which I added to the controller using the GetQueryList method (User string).

Everything works fine from the browser, I return my result, but from the script I get 403. I have already pursued my story for two days.

I omitted the methods to just make everything work.

Here is the controller code:

<AcceptVerbs(HttpVerbs.Get)> _ 
Public Function GetQueryList(ByVal user as String) as JsonResult   
    Return Me.Json(String.format("Hello {0}", user))
End Function

Client Code:

    $.getJSON("http://myservername.org/ClientQuery.mvc/GetQueryList",
        null
        , function (data) {
            alert(data);
        }
    );

If anyone has any ideas, it may save the fact that I have little left.

+3
source share
1 answer

You get this error because browsers implement the Same Origin Policy , which blocks AJAX requests for other domains.

You can create a local AJAX class to proxy an external AJAX request on behalf of the user using .NET WebRequest . Note that WebRequest does not have a constructor and uses the factory method instead WebRequest.create(Uri).

0
source

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


All Articles