When attempting to access a webservice that I've created in C# using Typescript and the fetch-api, everything works smoothly in Chrome and Firefox. However, in Edge, the access fails. I've tried both POST and GET methods in Edge, but neither are successful.
It's important to note that the Typescript/js/html is being run locally from disk! So, my Browser address field appears like this: file:///C:/Users/.../WebServiceConsumer/view/index.html
The Typescript method used to access the webservice is as follows:
getData(url:string, token?:string): Promise<any>{
let headers:Headers = new Headers({"Content-Type": "application/json"});
if (token) {
headers.set("Authorization", 'Bearer '+ token);
}
return fetch(url, {
method: "GET",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: headers,
redirect: "follow",
referrer: "no-referrer",
})
.then(response => response.json()
.then(json => {return json}))
.catch(error => console.log('error:', error));;
}
The webservice method being accessed looks like this:
public class SearchController : ApiController
{
[HttpGet]
[Route("api/v1/Search/Test")]
public IHttpActionResult Get()
{
return Ok("OK");
}
}
I have set the CORS Policy in my C# code using:
res.Headers.Set("Access-Control-Allow-Origin", "*");
The error message I receive and log to the console is shown here.
I am unsure of how to resolve this issue. What is Edge doing differently from Chrome? How can I access my webservice from Edge?
Just to let you know
- The webservice is a C# standalone app with Owin
- Accessing from "file:///..." is a requirement for this project