Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在iframe中显示本地文件夹中的html文件?_C#_Javascript_Jquery_Asp.net_Iframe - Fatal编程技术网

C# 如何在iframe中显示本地文件夹中的html文件?

C# 如何在iframe中显示本地文件夹中的html文件?,c#,javascript,jquery,asp.net,iframe,C#,Javascript,Jquery,Asp.net,Iframe,我尝试在iframe中显示html文件 html文件位于我的服务器上的本地文件夹中,具有相关权限(例如:c:\temp) 我试过: iframe = document.createElement("iframe"); iframe.src = "file:///c:\temp\a.html"; iframe.style.display = "block"; document.body.appendChild(iframe); 但内容不会显示在iframe中 我尝试的另一个解决方案是使用ajax

我尝试在iframe中显示html文件

html文件位于我的服务器上的本地文件夹中,具有相关权限(例如:
c:\temp

我试过:

iframe = document.createElement("iframe");
iframe.src = "file:///c:\temp\a.html";
iframe.style.display = "block";
document.body.appendChild(iframe);
但内容不会显示在iframe中

我尝试的另一个解决方案是使用
ajax
div
中显示html:

$("#DIV").html( *READ HTML TEXT FROM FILE *)
但这里的问题是,html页面中包含图片和css文件,它们无法显示,因为当前位置是我的网站(它们与html一起包含在
c:\temp
文件夹中)


有人知道如何在
iframe
中显示带有图像的html页面吗?

假设从根目录而不是临时目录加载html文件时,该页面工作正常(因此,排除了除文件位置问题以外的所有问题),只要您有访问权限,就可以加载与网站相关的文件。它确实需要了解您的路径-本地路径和服务器路径(如果适用)。例如,我在托管服务器上有一个名为“temp”的文件夹,该服务器是我网站的对等服务器

使用Request.PhysicalApplicationPath,我发现我的站点位于我的主机上:“c:\inetpub\wwwroot\mydomain.com\index.htm”。因此,我的临时文件夹和文件必须位于“c:\inetpub\wwwroot\temp\myfile.txt”(同样,temp是我站点的对等方)

粗略的例子:

string _filePath, _uriServerName = "";

_filePath = Request.PhysicalApplicationPath;
_uriServerName = Request.ServerVariables["SERVER_NAME"].ToLower();

if (_uriServerName != "localhost")
{
int rootPos = _filePath.IndexOf("wwwroot"); //get position wwwroot 
_filePath = _filePath.Substring(0, rootPos) + "temp\\myfile.txt";
}

我使用上述方法在网站外加载文件。为此,它工作得很好。但是,iframe可能会带来一些其他挑战。我不认为这会带来任何跨域问题,但我不能完全确定。

问题是浏览器看到了
file:///c:\temp\a.html
作为浏览器的本地文件,因此ts到C:访客的驱动力


您可以将该本地文件夹设置为网站的虚拟目录(在IIS中),并使用正确的web路径引用该文件(http://...)。这样您就不会移动文件夹,但它仍然可以通过web服务器使用。

我会将它们从临时文件夹中移到您的web根目录中的文件夹中。如果服务器允许您以您尝试的方式访问和显示服务器上的任何文件,则会出现严重的安全问题。您好@AdrianThompsonPhillips,谢谢!我可以访问ss只有一个具有特殊权限的特定文件夹。如果不从那里移动文件,我不能这样做吗?为了分析起见,从web根目录而不是临时目录加载html文件时,它是否正常工作?