I have two ASP.NET sites and one is a REST Web API. I am making a request to the API from the other website to get a PDF and display using Adobe Acrobat. Below is how I have configured the web API to use CORS in my startup file in production because these sites will be hosted together so for now I want to allow CORS;
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
I get an error
Access to XMLHttpRequest at 'https://localhost:44389/documents/test.pdf' from origin 'https://localhost:44382' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
As you can see I have configured CORS to accept from any origin and apart from that all API calls to fetch data into datatables are working. Below is the code to fetch the document using Javascript to use with Acrobat reader.
<script>
const viewerConfig = {
/* Allowed possible values are "FIT_PAGE", "FIT_WIDTH" or "" */
defaultViewMode: "",
};
/* Wait for Adobe Document Services PDF Embed API to be ready */
document.addEventListener("adobe_dc_view_sdk.ready", function () {
/* Initialize the AdobeDC View object */
var adobeDCView = new AdobeDC.View({
/* Pass your registered client id */
clientId: "dc02e57f9741b5a2ccd748bfc012ae3",
/* Pass the div id in which PDF should be rendered */
divId: "adobe-dc-view",
});
/* Invoke the file preview API on Adobe DC View object */
adobeDCView.previewFile({
/* Pass information on how to access the file */
content: {
/* Location of file where it is hosted */
location: {
url: "https://localhost:44389/documents/test.pdf",
},
},
/* Pass meta data of file */
metaData: {
/* file name */
fileName: "@viewDocument.DocumentTitle"
}
}, {
defaultViewMode: "FIT_WIDTH", showAnnotationTools: true, showLeftHandPanel: false,
showDownloadPDF: false, showPrintPDF: false
});
});
</script>
Are my CORS settings wrong or am I missing something?