使用 SharePoint Web 部件访问远程文件

发布于 2024-07-07 11:18:09 字数 386 浏览 7 评论 0原文

我最近构建了一个程序,可以解析 \some_server\c$\directory\file.xls 中的远程文件,它在我的本地计算机上运行得很好,就像普通的 aspx 页面一样。

然后我将程序放入Web部件中 我的 VM SharePoint 服务器上的表单 出现此错误:访问路径 '\some_server\c$\directory\file.xls' 被拒绝。

该文件已共享到域\经过身份验证的用户,所以我不确定为什么它会被拒绝? 我的 SharePoint 是否可能尝试使用本地或网络服务帐户调用它? 我怎样才能让它阅读? 谢谢。

I recently built a program that parses a remote file from \some_server\c$\directory\file.xls and it works fine on my local machine as just a normal aspx page.

Then I put the program into web part
form on my VM SharePoint server and I
get this error: Access to the path
'\some_server\c$\directory\file.xls'
is denied.

The file is shared to Domain\Authenticated Users so I am not sure why it would be denied? Is it possible my SharePoint is trying to call it with a local or network service account? How can I get it to read? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

海夕 2024-07-14 11:18:09

Salamander 是对的,SharePoint 并没有以信任的方式运行来执行此操作。

将 web.config 中的 SharePoint 信任级别从 WSS_Medium 更改为 Full 是快速解决方案,但存在安全隐患。

Salamander is right, SharePoint doesn't run with trust to do this.

Changing the trust level for SharePoint in it's web.config from WSS_Medium to Full is the quick solution, but there are security implications..

寂寞清仓 2024-07-14 11:18:09

请注意,您可能会遇到经典的 NTLM 双跳问题。 您可以向前端进行身份验证,但由于前端没有您的密码,因此它无法向另一台服务器上的资源进行身份验证。

使用提升的权限运行并根据应用程序池身份设置权限可能是推动您前进的一种方式。

Just a quick note, you could be running into the classic NTLM Double-Hop issue. You can authenticate to the front end, but because the front end does not have your password, it cannot then authenticate to a resource on another server.

Running with Elevated priviliges, and setting permissions based on the Application Pool identity could be one way of moving your forward.

初见终念 2024-07-14 11:18:09

我认为您将需要 RunWithElevatedPrivleges,这将使 SharePoint 使用应用程序池帐户。 另请记住,您必须确保应用程序池帐户有权访问该网络共享。 避免使用完全信任。

I think you will need RunWithElevatedPrivleges which will make SharePoint use the application pool account. Also keep in mind you will have to make sure that application pool account has access to that network share. Avoid using full trust.

黑色毁心梦 2024-07-14 11:18:09

您能否进一步解释一下设置信任级别到底对您有什么作用?

我认为,如果您的应用程序池身份是域帐户,您可以使用 SPSecurity.RunWithElevatedPrivileges 来使用应用程序池凭据来访问文件。 或者,使用模拟来显式传递另一个帐户的凭据。

Can you explain further what exactly setting the trust level does for you?

I would think that if your app pool identity is a domain account you can use SPSecurity.RunWithElevatedPrivileges to use the app pool credentials to access the file. Or, use impersonate to explicitly pass another account's credentials.

风为裳 2024-07-14 11:18:09

SharePoint 通常在单独的应用程序池中运行。 请检查该应用程序池的身份。

SharePoint usually runs in a separate application pool. Please check the identity of this application pool.

十年九夏 2024-07-14 11:18:09

我认为为了能够访问网络路径,您的代码必须在完全信任的情况下运行,但我认为 SharePoint 不会这样做。

I think to be able to access network path, your code has to run in FULL TRUST, which I don't think SharePoint does.

他是夢罘是命 2024-07-14 11:18:09

为什么不将该文件存储在 SharePoint 中以便您可以更好地访问它? 将其放入隐藏库并使用 SPSecurity.RunWithElevatedPrivledges 访问它。

RWEP 有一些注意事项。 从 SPContext(即 SPContext.Current.Site)获取的对 SPSite 和 SPWeb 的任何引用仍将在登录用户的权限下运行。 您必须在 RWEP 委托内显式创建引用。

SPSecurity.RunWithElevatedPrivileges(委托()
{
使用 (SPSite 站点 = new SPSite(SPContext.Current.Site.Url))
{
使用 (SPWeb web = site.OpenWeb())
{
//... 使用 SPWeb 做一些事情
}
}
});

如果您需要从外部共享点访问文件以使用现有进程更新它,您可以使用可用于所有 SPDocumentLibrary 的文件共享路径,但转到“操作 -->” 使用Windows资源管理器打开以获取网络路径。

Why not store the file in SharePoint so you have better access to it? Put it in a hidden library and access it using SPSecurity.RunWithElevatedPrivledges.

There are caveats to RWEP. Any reference to SPSite and SPWeb obtained from the SPContext (ie SPContext.Current.Site) will still run under the privledges of the logged on user. You must explicity create a reference inside the RWEP delegate.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
//... Do something with SPWeb
}
}
});

If you need to access the file from outside sharepoint to update it with existing processes you can use the file share path which is available for all SPDocumentLibrary's but going to Actions --> Open with Windows Explorer to obtain the network path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文