【问题标题】:C# MVC & React - react not fully loading on MS EDGE ( Cors error SEC7120)C# MVC & React - 在 MS EDGE 上反应未完全加载(Cors 错误 SEC7120)
【发布时间】:2018-11-01 04:40:23
【问题描述】:

我有一个带有一些 React 组件的 C# MVC 应用程序。 Chrome 工作正常,但 Edge 抛出 Origin https.... not found in Acces-Control-Allow-Origin Header

我已经阅读了与 CORS 和 MVC 相关的几乎所有内容,但找不到修复方法。

到目前为止我尝试过的 ->

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>

自定义 CORS 处理程序

    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 {....}

上述方法似乎都不起作用。 Edge 仍然会抛出 CORS 错误(即使它与同一域上的资源有关(可能与 npm 包或其他东西有关)。

有什么建议吗?

编辑:忘了提(也许会有所帮助)。此 console.log 确实会被触发,但除此之外没有任何内容。

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 ");

更新:我想我发现了我的问题所在(或另一个与惊人的 EDGE 相关的问题)。

问题可能是我加载了一个依赖于特定获取请求的列表(我正在构建一个共享点提供程序托管的加载项)。 MS Edge 似乎讨厌 OPTIONS Http 动词,因为它会抛出一个错误,说它不受支持....

知道如何解决这个问题吗?

【问题讨论】:

  • 你确定不是this answer on a similar question中提到的“本地Intranet区域”问题吗?
  • 很确定,因为我也在 azure 主机上对其进行了测试

标签: c# asp.net-mvc reactjs


【解决方案1】:

在浪费了很多时间之后,我认为错误是因为我正在做的fetch()

我安装了 axios,似乎axios.get() 没有任何错误。

【讨论】:

    猜你喜欢
    • 2019-12-12
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多