使用 Microsoft Edge 在 Visual Studio 中发布 运行 Web 应用程序

Issues Running Web App in Visual Studio using Microsoft Edge

我继承了一个使用 Angular 的 MVC 应用程序 (Visual Studio 2013),在 Microsoft Edge 中查看该应用程序时无法正常工作。

当浏览器设置为在 VS 中调试时使用 Microsoft Edge 时,我在主页加载时看到许多 toast 错误。我还发现了以下内容:

  1. 在任何“controller.js”文件中设置的任何断点都会导致“没有为此文档加载任何符号”。当浏览器设置为 IE 时,将命中断点。

  2. 在 Microsoft Edge 中查看开发人员工具的控制台时,我看到诸如“从源 'http://localhost:55798' 访问位于 'http://localhost:57113/api/todo' 的 XMLHttpRequest 已被 CORS 策略阻止的错误:请求的资源上不存在 'Access-Control-Allow-Origin' header。”这不会发生在 IE 中。

  3. 在web.config中,设置“LoginServiceName”值为http://localhost:55798/token,“RemoteServiceName”值为http://localhost:55798/api.我在整个应用程序中搜索“55798”并将其替换为端口 57113,但我仍然在第 2 点收到错误

  4. 已经部署到测试服务器的站点显示相同的错误,但是从 VS 部署到生产服务器的站点没有问题。

我已经阅读了一些关于 CORS 的帖子,但我不确定为什么该网站在生产环境中工作,但没有测试,而不是在 运行 它通过 VS 使用 Microsoft Edge 时。我也不明白为什么在 web.config 文件中设置 55798 时使用端口 57113,以及为什么当 55798 更新为 57113 时它仍在寻找 55798。

当我在解决方案中搜索“XMLHttpRequest”时,我看到 jquery-2.0.3.js/min.js 中有对它的引用。是否需要使用最新的 jquery 文件?

我试过添加

            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Headers" value="Content-Type" />

到我的 IISExpress applicationhost.config 文件,但这并没有解决问题。

当我使用 Microsoft Edge 开发人员工具单步执行代码时,它命中了 jquery-2.0.3.min.js 的第三行,完成后,显示 toast 错误,然后代码进入angular.js 文件。当我在开发人员工具中查看网络 > XHR 时,我看到请求 URL 是 http://localhost:57113/api/todo 并且在请求 Headers:

Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 0
Content-Type: application/x-www-form-urlencoded
Host: localhost:57113
Origin: http://localhost:55798
Referer: http://localhost:55798/
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Microsoft Edge";v="90"
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51

有什么想法吗?

根据您 Headers 的请求 post,您似乎使用的是已过时的 Edge 版本 90。我发现 similar issue 与以前版本的 Edge。它表明该问题已在较新版本的 Edge 中得到修复。能否请您将您的Edge浏览器更新到最新的96版本再测试一下?如果问题在最新版本的 Edge 中得到修复,请告诉我们测试结果。