【发布时间】:2022-01-13 04:35:48
【问题描述】:
我要做的是从服务器查找共享文件夹,并在目录中找到一个文件并将其下载到我的客户端桌面。
从服务器下载到我的虚拟机桌面可以正常工作,但是,它不能下载到我的客户端桌面。它只是抛出一条错误消息,指出目标路径访问被拒绝。不知道为什么,因为当我从作为本地运行的虚拟机尝试它时,它工作得很好。但是,如果我部署到我们的开发服务器,那么它会抛出该错误消息并且不会下载到我的客户端桌面。
我研究发现由于安全问题,它永远不会下载到客户端桌面,但是有没有办法从服务器下载到客户端桌面?
#1。找到我要的文件后,从服务器获取
if (!File.Exists(thisFile))
{
string serverSourcePath = Path.Combine(finalResourcePath + thisFile + ".pdf");
//What I'm trying to do here is that since the client desktop path starts with C:\\Users\MyCredentials\Desktop\... just get the credentials from the user
string userName = User.Identity.Name.Replace("CompanyName\\", "");
string destinationFilePath = Path.Combine(@"C:\Users\" + userName + @"\Desktop\" +
thisFile + ".pdf");
using (var client = new WebClient() { UseDefaultCredentials = true })
{
try
{
client.DownloadFile(serverSourcePath, destinationFilePath);
}
catch (Exception ex)
{
return BadRequest(ex.InnerException.Message);
}
}
}
【问题讨论】:
-
你说,你部署到服务器上?如果您在 Windows 和 IIS 或 Linux 和 kestrel 上运行 Web 应用程序的用户需要写入目标文件夹的权限。
-
所以我为所有尝试从共享文件夹下载文件的用户提供了完全控制权。只要他/她在我们的域下并使用 Windows 凭据。我必须授予哪些权限?
标签: c# asp.net-mvc