Requirement: The page needs to display an image, but due to various reasons, the image is on server 2, but the program to be displayed is on server 1. This causes a cross-domain problem when displaying. The original idea is to directly write a program to obtain the image path in the background, then download the image, and then return the image address to server 1. However, due to the uncertainty of this cycle and the urgency of the project at this stage, it was abandoned. Switch to the second method and download the image to the server through js. . After looking for some information and communicating with others, I found that it could not be realized. Then I planned to use js+canvas to save it locally, but then I found that it seemed that it could only be saved locally. Then the problem returned to the starting point: Is it possible to directly introduce pictures when they already exist on the website? After consulting the information and carefully analyzing it, after testing and debugging, the problem of accurately implementing the introduction of pictures was solved. Process: Cross-domain solution for image import Result: Change the webconfig settings to solve the cross-domain problem <?xml version="1.0" encoding="utf-8"?> <!-- For more information about how to configure ASP.NET applications, visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> <customErrors mode="Off"/> Here you can also see the error log in the external network <webServices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols> </webServices> </system.web> <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/> <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type"/> <add name="Access-Control-Allow-Origin" value="*, http://192.168.0.178:8068" /> </customHeaders> </httpProtocol> </system.webServer> The main problem is the restriction of cross-domain access permission set as above. In this way, the cross-domain problem can be solved when displaying pictures on server 1. How to set cross-domain in IIS web.configIn website development, there is sometimes a need for cross-domain, so how does IIS set up cross-domain? We can configure it directly in the web.config file. The setting method is as follows: <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/> <add name="Access-Control-Allow-Headers" value="x-requested-with"/> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> </system.webServer> By setting the above web.config, we can achieve cross-domain website. Here is a sharing of the cross-domain IIS webconfig IIS setting methodSet Access-Control-Allow-Origin Open IIS, find "HTTP Response Header" and click it. You can see Add on the right, then add the following header
as follows <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/> <add name="Access-Control-Allow-Headers" value="x-requested-with,Content-Type"/> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> </system.webServer> This is the end of this article about how to set up cross-domain access in IIS web.config. For more information about IIS cross-domain access, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: Detailed explanation of HTML document types
>>: Detailed explanation of the MySQL MVCC mechanism principle
Table of contents 1. The following code is a simp...
I remember when I was interviewing for my current...
Using mask layers in web pages can prevent repeat...
background I am often asked about database transa...
Why is the title of the article “Imitation Magnif...
This article records the installation and configu...
Table of contents Overview Checking setTimeout() ...
Table of contents Configuration parsing Service C...
After VMware is abnormally shut down, it prompts ...
Table of contents 1. View hook 1. Things to note ...
CSS3 implements 2D plane transformation and visua...
This article uses examples to describe the common...
Table of contents 1. Select All 2. Increase or de...
1. Naming conventions 1. Database names, table na...
Table of contents 1. Basic configuration of Nginx...