尝试通过 WebClient 访问 SharePoint 列表中的文件时收到 403 响应
我正在尝试使用 System.Net.WebClient 访问 SharePoint 列表中的文件。该列表已禁用匿名访问(当我们打开它时,它会起作用)并且我们正在使用基于声明的身份验证。我知道还有其他方法可以访问 SharePoint 列表中的文件,但是这是关于我对 Office Web Apps Web 服务进行的调用,在该调用中我必须传递文件的 URL,我希望它生成该文件的图像。使用此 URL 调用 OWA Web 服务并尝试通过 WebClient 直接下载文件都会产生相同的错误。
该错误是 403 禁止,经过一番谷歌搜索后,我相信原因在某种程度上与使用基于声明的身份验证有关。我已经尝试了一些建议的补救措施,但到目前为止没有任何效果。我可以使用浏览器访问该文件和 Web 服务,并且在收到身份验证质询后即可正常工作。如果我故意未通过身份验证质询,则会收到 401 错误(而不是 403),因此我不认为凭据有任何问题(我已经对它们进行了硬编码)。我尝试使用 RunWithElevated Privileges 运行代码,但这没有帮助。
这是一些示例代码:
using (var webClient = new WebClient()) { webClient.UseDefaultCredentials = true; byte[] result = webClient.DownloadData(urlOfFileInList); }
感谢任何帮助!
I’m trying to access a file in a SharePoint list using System.Net.WebClient. The list has anonymous access disabled (when we turn it on, it works) and we’re using Claims-Based Authentication. I know that there are other ways of accessing a file in a SharePoint list, however this is regarding a call that I make to an Office Web Apps web service where I have to pass the URL of a file I want it to generate an image of. Both calling the OWA web service with this URL and trying to download the file directly via WebClient yield the same error.
The error is 403 forbidden, which after some googling I believe the cause is somehow related to using Claims-Based Authentication. I’ve tried a number of the suggested remedies, but so far nothing has worked. I can access the file and the web service using a browser and it works after I get an authentication challenge. If I fail the authentication challenge intentionally I get a 401 error (not a 403), so I don’t believe there’s anything wrong with the credentials (I’ve gone so far as to hard-code them). I’ve tried running the code with RunWithElevated Privileges, but that doesn’t help.
Here is some sample code:
using (var webClient = new WebClient()) { webClient.UseDefaultCredentials = true; byte[] result = webClient.DownloadData(urlOfFileInList); }
Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能必须使用 WebClient 进行声明登录,看看是否可以以此为起点。
You might have to do the claims login with WebClient, see if you can use this as a starting point.
将 SharePoint OM 与 WIF 结合使用会带来更好的运气。
此处提供了一个示例:
http://www.shailen.sukul .org/2010/07/adfs-20-and-sharepoint-client-om.html
You will have better luck using the SharePoint OM with WIF.
An example is available here:
http://www.shailen.sukul.org/2010/07/adfs-20-and-sharepoint-client-om.html