1

I have a C# MVC app with some React components. Chrome works fine, but Edge is throwing a Origin https.... not found in Acces-Control-Allow-Origin Header

I've read pretty much everything related to CORS and MVC, but can't find a fix.

What i've tried so far ->

Web.Config

<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type" />
    <add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
    <add name="Access-Control-Allow-Credentials" value="true" />
  </customHeaders>
</httpProtocol>

Custom CORS handler

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*");
        filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-Headers", "*");
        filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-Credentials", "true");

        base.OnActionExecuting(filterContext);
    }


[AllowCrossSite]
public class ReactController : Controller {....}

None of the above seem to be working. Edge still throws the CORS error (even tho' its about a resource on the same domain (perhaps related to npm packages or something).

Any tip?

Edit: Forgot to mention (perhaps it will help). This console.log does get triggered, but nothing beyond that point.

import * as React from 'react';
import { TextField } from 'office-ui-fabric-react/lib/TextField';
import { DetailsList, DetailsListLayoutMode, Selection, buildColumns } from 'office-ui-fabric-react/lib/DetailsList';
import { MarqueeSelection } from 'office-ui-fabric-react/lib/MarqueeSelection';
import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox';
import { createRef } from 'office-ui-fabric-react/lib/Utilities';
import { initializeIcons } from 'office-ui-fabric-react/lib/Icons';
import { css, classNamesFunction } from 'office-ui-fabric-react/lib/Utilities';
import { DefaultButton, IButtonProps } from 'office-ui-fabric-react/lib/Button';
import { Label } from 'office-ui-fabric-react/lib/Label';

initializeIcons(/* optional base url */);
console.log("Initialized ");

UPDATE: I think i found out where my problem is (or another one related to the amazing EDGE).

The problem might be the fact that im loading a list that depends on a specific fetch request (im building a sharepoint provider hosted add-in). MS Edge seems to hate the OPTIONS Http Verb as it throws an error saying it is not supported....

Any idea on how i could fix this?

Dante R.
  • 902
  • 3
  • 13
  • 41
  • Are you sure it's not the "local intranet zone" issue recounted in [this answer on a similar question](https://stackoverflow.com/a/35272831/215552)? – Heretic Monkey Oct 31 '18 at 17:43
  • Pretty sure since i tested it on azure host as well EDIT: Also not sure why it shows as CORS since the failing request is on the same domain (same app even) – Dante R. Oct 31 '18 at 18:15

1 Answers1

0

As i thought after a lot of wasted time the error was because of the fetch() that i was doing.

I installed axios and it seems that axios.get() works without any kind of error.

Dante R.
  • 902
  • 3
  • 13
  • 41