Cross domain & Cross Origin

8 minutes
Share the link to this page
Copied
  Completed

Transcript

Hello guys, welcome to the 23rd session of the years we don't need VBA to in a previous session where we center the AJAX request from the same origin. In this session we are learn how to handle the AJAX request from the cross domain access. Let's first understood what is the same origin policy. All of the browser follow the same origin policy. If both webpage origin from the same domain and a web server, then the browser can access the second page data through the first page. Origin could be a combination of the hostname port number and the URL scheme.

In the below example, for sure you are have the same origin. What are the last three you are How are different origin from the first one. You can see that in the third URL. We are used a different port number. India for two years, we have the ability vs instead of the ITP. And in a fifth URL, there is a different domain name.

So if you want to access the URL from the Roman, then we need to modify the our API. Let's first create a new solution from which we are sending the request to the our API. Let's open the new instance of the Visual Studio. Click on the new project select the ASP. NET web application. I am using a cross domain as a project name.

Select the MVC and click OK. I'm selecting the MVC instead of the empty project just because of the MVC project contain the reference radiology query, whether empty project does not contain the reference to the ECI query. library Hello project is created. Let's add one new HTML page by clicking Add HTML with the name. So all data dot html I'm going to switch to the old project and copy the entire data and replace it with the new project. See we build it now I'm going to click on the source data button.

You can see that an arrow and control method that occur that we are right on error handler or the our jQuery Ajax request. Let's open the inspect element and click on the console tab. You can see that the cross origin request blog the same origin policy de cielo to creating the remote resource In these course header is missing. This error can be handled by the two ways. The first way is to use this NP and another is used the course. In this lesson we are going to use the HMP.

This NP stands for JSON with deep reading, it is a way to get the data from the another domain that bypass the across original resource. Jason P is JSON data with the callback function. In the below example, you can see that the image on the left hand side represent the our data in the form of VHS and where the image on the right hand side represent the data in the form of the SNP. You can see that it only added the callback function name, and within the parentheses we specify the origin format. Let's modify the our VBA says that it returned the HS MP switch to the project. Stop it.

From the click on the click on the project tab click on the project, select the Manage nougat package. Within a nougat package, we will need to search about the s&p 500 which we need to install the VBA contribute dot formatting dot Jason p, Click on the Install button. It will install the formatting for the edges NP as well as it's all dependency that required by it and click on the OK. You can see that the Jason p formatting was installed successfully. After the installation we need to specify that the word VBA also support the formatting for the edges and P for that To open the app underscore start VBA config. First of all we need to create the instance of the Jason media type formatter for that I am going to write over Jason V for Mater equal to new. Jason, we really are I, for me, which was a present in a different namespace, so we need to use a using statement.

And within the parentheses we need to pass the our Jason media type formatter. For that we need to write config dot formatters dot Jason formatter. And after this, we need to add our Jason formatter within the configuration. For that, I'm going to write config Door four meters dot insert. Jason we formatter on the zero index and let's run it copy the URL, paste it API s last employee and click on Send. You can see that it treated the 500 internal server error.

Let's see preview. a callback parameter was not provided by the requester UI. When we want to receive the data in the form of GCP. We must need to specify the callback parameter for that we need to write a question mark called back equal to Some matter, I click on the Send, you can see that it returned the status 200. And all of the data that we received previously within the JSON format that exists with the callback function that is some method that we specify within the parameter. Let's switch to the cross domain solution.

Instead of using the ages and we need to use the H SNP load to a previous page. Click on the saw Data button. You can see that it was received the data successfully. However, the port of the both of the application is a different means they both are running on the different origin shell we are able to access the data by using the s&p For using the HS MP formatter, first of all, we need to add the VBA contrib dot formatting dot Jason from the nougat and add the below line in the VBA config.cs file that present in the app underscore start. We need to create the instance of the ages and P media type formatter and here within the parentheses we need to specify the our Jason formatter and do Jason p formatter with indeed our config dot formatters. Thanks for watching, have a nice day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.