简体   繁体   English

WebClient.DownloadFile在本地工作,但不在服务器WS2008 R2 IIS7上

[英]WebClient.DownloadFile working locally but not on server WS2008 R2 IIS7

I am using below 我在下面使用

var inputPath = "file:" + fileName.Replace(@"\", @"/");
var uri = new Uri(inputPath);
var client = new WebClient();
client.DownloadFile(uri, downloadPath);

The "file://*" with filename opens in browser directly. 带文件名的“ file:// *”直接在浏览器中打开。

The file is housed on the server and able to be accessed and download when run from DEBUG in VS2012 using my localhost but when I type in the browser to connect to the DEV server version it will not download the file. 该文件位于服务器上,使用我的本地主机从VS2012中的DEBUG运行时可以访问和下载,但是当我在浏览器中键入连接到DEV服务器的版本时,它将不会下载该文件。

The app pool is running under my name because I cannot get the app pool to work under AppPoolIdentity. 应用程序池以我的名字运行,因为我无法让该应用程序池在AppPoolIdentity下工作。 I have Full Control of folder path for the file location. 我可以完全控制文件位置的文件夹路径。 So does ANONYMOUS and Everyone just in case all of this was a security issue. 万一所有这都是安全问题,匿名和所有人也是如此。

Since its a DEV box I have even removed the Firewall completely to see if the Firewall was blocking the download. 由于它是一个DEV框,我什至完全删除了防火墙,以查看防火墙是否阻止了下载。

When I run from the Chrome browser and F12 I can see that the section of code has a Status Code of 200 'OK' when the DownloadFile runs, so there is no error it just doesn't save to my downloadPath location. 当我从Chrome浏览器和F12运行时,当DownloadFile运行时,我看到的代码部分的状态代码为200'OK',因此没有错误,只是它没有保存到我的downloadPath位置。

Please advise if you have seen this before. 请告知您是否曾经看过。

Thid might be a proxy settings problem: 这可能是代理设置问题:

<configuration>
 <system.net>
  <defaultProxy>
   <proxy
    usesystemdefaults="true"
    proxyaddress="http://192.168.1.10:3128"
    bypassonlocal="true"
   />
   <bypasslist
    <add address="[a-z]+\.contoso\.com" />
   </bypasslist>
  </defaultProxy>
 </system.net>

see settings here 在这里查看设置

Or you could examine the problem using fiddler . 或者,您可以使用提琴手检查问题。

After tons of looking I found a work around that may be obvious to others. 经过一番寻找,我发现周围的工作对其他人可能是显而易见的。 I was trying to use ajax calls to call the Action to download the file. 我试图使用ajax调用来调用Action来下载文件。 This seemed to just sit but there was no error so in F12 once I clicked on the call that showed in the logs the file downloaded. 这似乎只是坐着,但没有错误,因此在F12中,一旦我单击了在日志中显示的下载文件的调用,就可以了。

I have moved my process to use href for "http://ip/website/action?fileName=" + fileName 我已将过程移至将href用作"http://ip/website/action?fileName=" + fileName

This uses the default download functions of the browser you are in so it works for Chrome and IE. 这将使用您所用浏览器的默认下载功能,因此适用于Chrome和IE。 I have not tried Firefox yet. 我还没有尝试过Firefox。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM