如何在 Sharepoint Online 中启用 CORS

编程入门 行业动态 更新时间:2024-10-17 22:26:25
本文介绍了如何在 Sharepoint Online 中启用 CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在我的 React 应用程序中实现共享点文件浏览器.将 microsoft/file-browser 用于此 ans 代码,如下所示.但是从源 'localhost:3000' 获取 xxx... 已被 CORS 策略阻止

I am trying to implement share point file browser in my react application. Using microsoft/file-browser for this ans code as follows. But getting the xxx... from origin 'localhost:3000' has been blocked by CORS policy

任何想法如何为此启用 CORS

Any ideas how can I enable CORS for this

import * as React from "react"; import { GraphFileBrowser } from '@microsoft/file-browser'; class App extends React.Component { getAuthenticationToken() { return new Promise<string>(resolve => { resolve( "VALID TOKEN" ); }); } render() { return ( <GraphFileBrowser getAuthenticationToken={this.getAuthenticationToken} onSuccess={(selectedKeys: any[]) => console.log(selectedKeys)} onCancel={(err: Error) => console.log(err.message)} endpoint='XXX.sharepoint' /> ); } } export default App;

推荐答案

据我所知,CORS 错误不是因为 SharePoint 而发生,而是因为您的浏览器.这里的问题是您正在尝试将资源从 xxx.sharepoint 加载到 localhost(默认情况下,CORS 中永远不会添加该资源)

As far as i can tell the CORS error does not occur because of SharePoint, but because of your Browser. The problem here is that you are trying to load resources from xxx.sharepoint to localhost (which per default is never added as accepted in CORS)

因此,一种解决方案是使用对 CORS 不敏感的浏览器.这可能是以下内容:

So one solution would to use a CORS-unsensitive browser. This could be the following:

cd "C:\Program Files (x86)\Google\Chrome\Application" chrome.exe --disable-web-security --user-data-dir="C:\tmp"

此代码段使用用户数据目录C:\tmp"在没有网络安全"(包括 CORS)的情况下启动您的 Google Chrome.

This snippet starts your Google Chrome without "Web Security" (includes CORS) using the User Data Directory "C:\tmp".

请记住,此解决方法仅适用于开发.在生产中你不应该使用 localhost...

Remember that this workaround only works for development. In production you should not use localhost...

www.thepolyglotdeveloper/2014/08/bypass-cors-errors-testing-apis-locally/

更多推荐

如何在 Sharepoint Online 中启用 CORS

本文发布于:2023-11-24 20:41:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626744.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Sharepoint   CORS   Online

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!