In this article, we will learn:
- What is CORS?
- How CORS works?
- How to solve cross origin request in WCF Rest
What is CORS?
Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the resource originated.
CORS defines a way in which a browser and server can interact to safely determine whether or not to allow the cross-origin request. It allows for more freedom and functionality than purely same-origin requests, but is more secure than simply allowing all cross-origin requests
Reference books, you may like:Programming WCF Services: Design and Build Maintainable Service-Oriented Systems
WCF Multi-Layer Services Development with Entity Framework, 4th Edition
Learning WCF: A Hands-on Guide
How CORS works?
The CORS standard describes new HTTP headers which provide browsers and servers a way to request remote URLs only when they have permission. Although some validation and authorization can be performed by the server, it is generally the browser’s responsibility to support these headers and respect the restrictions they impose.
you can read more on CORS here.
How to solve CORS issue in WCF Rest?
Let’s say you have a WCF rest service and you are trying to consume the service from a web client. You will get below error.
“No Access-Control-Allow-Origin header is present on the required resource”
If you are seeing this erro, that means the service is running on a different server and it is not configured to accept a request from any origin.
This error can be resolved by enabling CORS: Cross Origin Resource Sharing for the service.
© 2015, admin. All rights reserved.