如何将文件从我的网络服务器下载到我的桌面?
我已经在互联网上浏览了 3 个小时,现在正在寻找解决我的问题的方法,我开始想知道是否还有其他人遇到过这个确切的问题?
我正在使用 IIS7 托管一个网站,该网站在我们办公室周围执行一些本地操作。好吧,开发网站一切正常,但现在我正在托管该网站,我无法(其他任何人也无法)单击链接来下载所需的文件。 (假设他们点击一个链接从网络服务器下载一些随机文件)
好吧,它无法下载文件,我猜这是一个权限错误。我一直在寻找解决方案,但似乎找不到。我对 IIS7 知之甚少,所以我不太了解应用程序池身份的内容,尽管我确实设法授予该身份对文件/文件夹的完全访问权限。无论如何,这是它搞乱的特定区域。
这是 default.cshtml 页面的一部分,它从 .cs 文件调用函数: //好吧..非常接近确切的事情,刚刚摆脱了一堆不必要的垃圾
@{
string tmp = Functions.downloadFile(fileName)
}
<html>
tmp
</html>
这是.cs文件的一部分,实际将文件下载到桌面
public static string downloadFile(string fileName) //i know this example doesnt
//use filename, but the original code does.
{
if (Directory.Exists("C:\WebSite\thingsToDownload"))
{
string[] files = Directory.GetFiles("C:\WebSite\thingsToDownload");
foreach (string s in files)
{
string[] tmp = s.Split('\\');
try
{
File.Copy(s,
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
+ "\\" + tmp[tmp.Length - 1]);
}
catch (Exception e)
{
return "ERROR COPYING: " + e.Message;
}
}
return "GOOD";
}
return "DIRECTORY DOESNT EXIST";
}
在这一切都说完了之后,我得到“错误”复制:对路径“\fileName”的访问被拒绝。
我的猜测是网络服务器无权访问该人的桌面以将文件放在那里。 如果有人能阐明并帮助我得到这个,我将不胜感激!
I have looked around the internet for 3 hours now looking for a solution to my problem and I'm starting to wonder if anyone else has ever had this exact problem?
I am using IIS7 to host a website that does some local things around our office. Well, developing the site everything worked fine, but now that I am hosting the site I cannot (and neither can anyone else for that matter) click on the link to download the file that is needed. (lets just pretend they click on a link to download some random file from the webserver)
Well, it fails downloading the file from what I can guess as being a permissions error. I have looked for a solution but cannot seem to find one. I know very little about IIS7 so I do not understand very much about the Application Pool Identity stuff, although I did manage to grant full access for that identity to the file/folders. Anyways, here is the specific area it is messing up on..
This is a piece of the default.cshtml page that calls a Function from a .cs file:
//well.. pretty close to the exact thing, just got rid of a bunch of unecessary junk
@{
string tmp = Functions.downloadFile(fileName)
}
<html>
tmp
</html>
This is the part of the .cs file that actually downloads the file to the desktop
public static string downloadFile(string fileName) //i know this example doesnt
//use filename, but the original code does.
{
if (Directory.Exists("C:\WebSite\thingsToDownload"))
{
string[] files = Directory.GetFiles("C:\WebSite\thingsToDownload");
foreach (string s in files)
{
string[] tmp = s.Split('\\');
try
{
File.Copy(s,
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
+ "\\" + tmp[tmp.Length - 1]);
}
catch (Exception e)
{
return "ERROR COPYING: " + e.Message;
}
}
return "GOOD";
}
return "DIRECTORY DOESNT EXIST";
}
After that is all said and done, i get "ERROR COPYING: Access to the path '\fileName' is denied.
My Guess is that the webserver does not have access to the person's desktop in order to put the files there.
If anyone can shed some light and help me get this it would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想通过单击链接来下载文件,您应该使用响应。
这是一个示例,您可以在用户单击链接或按钮或其他内容时使用:
If you want to download a file by clicking a link you should use response.
Here's a sample you can use for example when a user clicks a link or button or something:
当您开发它时它就起作用了,因为它在您的计算机上运行,因此可以访问您的桌面。不存在下载到桌面这样的事情。您可以提供文件并让用户决定将文件保存在哪里;在桌面或其他地方。但您必须通过 http 来执行此操作,而不是直接从服务器执行此操作。
It worked when you developed it, because it was running on your computer and thus had access to your desktop. There is no such thing as download to desktop. You can serve files and let the user decide where to save the file; on the desktop or elsewhere. But you have to do this over http, not directly from the server.