This article is a mirror article of machine translation, please click here to jump to the original article.

View: 50738|Reply: 2

[Source] ASP.NET Allows cross-domain OPTIONS requests

[Copy link]
Posted on 2020-8-5 20:54:24 | | | |
When a browser requests resources from a web page of one domain name to another domain name, the domain name, port, and protocol are any different, and they are cross-domain.

I have written a lot about cross-domain myself, as follows:

Spring Boot allows cross-domain configuration
https://www.itsvse.com/thread-5075-1-1.html
nginx cross-domain resource sharing CORS to add response headers
https://www.itsvse.com/thread-3377-1-1.html
CORS setting WebApi cross-domain issue
https://www.itsvse.com/thread-3858-1-1.html
There are also specific descriptions of what cross-domain is:

What is cross-domain? How to solve cross-domain?
https://www.itsvse.com/thread-3868-1-1.html
The Cross-Domain Resource Sharing Standard adds a new set of HTTP header fields that allow the server to declare which origins have access to which resources through the browser. In addition, the specification requires that for HTTP request methods that may have side effects on server data (especially HTTP requests other than GET, or with some MIME types of POST requests), the browser must first initiate a preflight request using the OPTIONS method to know whether the cross-domain request is allowed by the server. The server confirms that it is allowed before making the actual HTTP request. In the return of a preflight request, the server can also inform the client if it needs to bring identity credentials (including cookies and HTTP authentication-related data).

HTTP Access Control (CORS)

The hyperlink login is visible.

Last weekend, on my blog introduction page, I returned the title of the article to the user in the form of calling the interface, because it was called to other second-level domain names, so there was a cross-domain problem, the interface was accessed through a POST request, and I forgot to set the OPTIONS request at the beginning, so the error was reported as follows:



The interface is written asp.net mvc controller, so you only need to add another OPTIONS request and allow cross-domain, the code is as follows:

access-control-allow-headers: *
access-control-allow-methods: GET, POST, PUT, DELETE
access-control-allow-origin: *
cache-control: private
content-length: 0
date: Wed, 05 Aug 2020 12:43:22 GMT
status: 200


(End)




Previous:SSIS Tutorial (7) SQL Server 2012 Executes SSIS Jobs
Next:Tencent, Hexun.com, Sina, Snowball, NetEase stock interface data
Posted on 2021-10-26 14:30:23 |
Thank you~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Landlord| Posted on 2025-2-17 11:25:24 |
ASP.NET Core allows cross-domain (CORS) requests
https://www.itsvse.com/thread-10007-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com