c# - 将凭据传递给 ASP.NET 4.0 和 IIS7 中的 File.Move()

标签 c# asp.net iis-7

我有一个在 IIS7 上运行的 asp.net Web 应用程序,其 AppPool 标识设置为“网络服务”,托管管道模式 = 经典。

web.config 包含以下安全设置...

<system.web>
    <identity impersonate="true"/>
    <authentication mode="Windows" />
</system.web>

Web 应用程序从第三方下载数据并在 Web 应用程序服务器上创建文件。然后通过此命令将这些文件传输到另一台服务器。

  System.IO.File.Move(sourcePathAndFilename, destinationPathAndFileName);

当我以高级用户身份从服务器运行该应用程序时,它工作正常。 当我以任何用户身份从客户端计算机运行该应用程序时,它会失败。 当我从服务器以低级别授权用户身份运行该应用程序时,它会失败。

错误是 HTTP 401 未经授权的访问。

我 100% 确定用户和网络服务对源文件夹和目标文件夹都拥有足够的权限。所以,看起来 File.Move() 命令正在作为其他命令执行,但是谁/什么?

在不更改 AppPool 设置的情况下,Web 应用程序是否可以将用户凭据传递给 File.Move() 命令?

最佳答案

您可以在this中找到您需要的一个很好的实现。问题

使用 using 语句添加特定类后,您可以执行 File.Move

只是

using (new NetworkConnection(@"\\server\path", Credentials)) {
   System.IO.File.Move(sourcePathAndFilename, destinationPathAndFileName);
}

关于c# - 将凭据传递给 ASP.NET 4.0 和 IIS7 中的 File.Move(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27567163/

相关文章:

c# - 显示非线程安全任务的 “Please Wait”对话框

asp.net - 如何在 Azure 中编辑网站应用程序设置

c# - 500.19 - 内部服务器错误 - 无法访问请求的页面,因为该页面的相关配置数据无效

asp.net - 限制IIS7中的asp.net session

asp.net - 在 ASP.NET Web 应用程序中存在未处理的异常是否可以接受?

c# - CSS 不工作

c# - 测试继承的 C# 类

asp.net - 根据 MS Access 查询的结果设置 gridview 列的值

asp.net - Linq Any() 超时

c# - 如何从在 UWP 应用程序中运行 IoT Core 的 Raspberry Pi 访问网络共享