遇到网络错误以检查文件是否存在 [英] Got network error to check if a file exists

查看:126
本文介绍了遇到网络错误以检查文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到网络错误,检查是否存在使用该段代码的文件(来自 [ ^ ]如下:

 function UrlExists(url){//其中url ='http:// xxxxx / fileName.png'
var http = new XMLHttpRequest();
http.open('HEAD',url,false);
http.send();
返回http.status!= 404;
}



如何调试此网络错误?

我也尝试了另一种方法,如下所示:

  var  fso =  new  ActiveXObject(  Scripting.FileSystemObject); 
fileBool = fso.FileExists( \\myNetworkFolder \ myFile.png );



但即使我使用IE作为浏览器,也可以创建目标。如何使用ActiveXObject?

如果你能提供帮助,谢谢。



我尝试了什么:



网络错误检查文件是否存在

解决方案

这个名字,\\ myNetworkFolder \ myFile.png,通常无法从Web应用程序访问。这是可以访问的 UNC 路径名,特别是通过同一LAN的其他主机执行的Windows 共享服务

路径(计算) - 维基百科,免费的百科全书 [ ^ ]。



但是服务器端代码在沙盒环境中执行,该环境仅允许访问为站点设置的根目录下的文件系统对象。这是出于严重的安全原因。


如果你真的想在单独的主机上存储图像,那么有一些(可能更重的)替代品。首先,请参阅:

将网站连接到UNC网络共享 [ ^ ]。



此外,您可以通过标准FTP服务器或其他HTTP服务器在其他主机上提供这些图像。您可以通过Web应用程序的服务器端代码访问数据:

FtpWebRequest类(System.Net) [ ^ ],

HttpWebRequest Class(System.Net) [ ^ ],

< a href =https://msdn.microsoft.com/en-us/library/system.net.webrequest%28v=vs.110%29.aspx> WebRequest Class(System.Net) [< a href =https://msdn.microsoft.com/en-us/library/system.net.webrequest%28v=vs.110%29.aspxtarget =_ blanktitle =New Window> ^ ]。



但首先,我会考虑将所有这些图像移到本地您网站的一部分。为什么不保持简单



- SA

I got Network error to check if a file exists using the piece of code (sourced from )[^]below:

function UrlExists(url) {   // where url = 'http://xxxxx/fileName.png'  
    var http = new XMLHttpRequest();
    http.open('HEAD', url, false);
    http.send();
    return http.status != 404;
}


How to debug this Network error?
I also tried an alternative approach as shown below:

var fso = new ActiveXObject("Scripting.FileSystemObject");
fileBool = fso.FileExists("\\myNetworkFolder\myFile.png");


But the objective can' be created even though I use IE as the browser. How can the ActiveXObject be used?
Thanks if you can help.

What I have tried:

Got Network error to check if a file exists

解决方案

This name, "\\myNetworkFolder\myFile.png", is not generally accessible from the Web application. This is the UNC path name which might be accessible, in particular, through the Windows sharing service executed by other hosts of the same LAN:
Path (computing) — Wikipedia, the free encyclopedia[^].

But the server-side code is executed in the sandboxed environment which only allows access to the file system objects under the root directory set up for your site. This is done for serious security reasons.

If you really want to store images on a separate hosts, there are some (potentially heavier) alternatives. First of all, please see:
Connecting Web Sites to UNC Network Shares[^].

Also, you can serve-up those images on another host through as standard FTP server or another HTTP server. The you can access the data by your Web application's server-side code:
FtpWebRequest Class (System.Net)[^],
HttpWebRequest Class (System.Net)[^],
WebRequest Class (System.Net)[^].

But first of all, I would think about moving all these images to the location of your Web site. Why not keeping it simple?

—SA


这篇关于遇到网络错误以检查文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆